SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2012
    Location
    Poole, Dorset, United Kingdom
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to remove a variable value from an array

    Hi All
    I'm sorting an array to get the lowest value and highest as below but want to exclude a set value ie 99. How could I do this ?

    $min = min(array($monStart, $tuesStart, $wedStart ,$thursStart, $friStart, $satStart, $sunStart));
    $max = max(array($monFinish, $tuesFinish, $wedFinish ,$thursFinish, $friFinish, $satFinish, $sunFinish));

    Many thanks

    Steve

  2. #2
    SitePoint Evangelist
    Join Date
    Oct 2005
    Location
    Michigan, USA
    Posts
    434
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Have a look at array_diff(). You'll need to make another array of the "exclude" values.

    Or, array_search() with unset() if you have just one value to exclude (but the above will also work for that case).
    - Robert

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2012
    Location
    Poole, Dorset, United Kingdom
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cheers Mate, I have a look. Thanks for the quick reply

  4. #4
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    71 Post(s)
    Tagged
    0 Thread(s)
    or since 99 is the highest value in your list (from previous thread), you could just modulo all values in the max array by 99, which would reduce any such entry to being 0, and thus not the max.

    Note that this only works because 99 is the highest value.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  5. #5
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,134
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by StarLion View Post
    or since 99 is the highest value in your list (from previous thread), you could just modulo all values in the max array by 99, which would reduce any such entry to being 0, and thus not the max.

    Note that this only works because 99 is the highest value.
    Only problem with that is you can no longer tell the difference between 0 and 99. So if you values are 0, 0, 0, 1, 99, you have 0, 0, 0, 1, 0. You may include the 99 result even though now it is rated as 0.

  6. #6
    SitePoint Enthusiast
    Join Date
    Apr 2012
    Location
    Poole, Dorset, United Kingdom
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It doesn't have to be 99, I am using a 24 hour clock for hours available each day and have set 99 as a closed day, but need to exclude this number as it will always show as the highest

  7. #7
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    71 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cpradio View Post
    Only problem with that is you can no longer tell the difference between 0 and 99. So if you values are 0, 0, 0, 1, 99, you have 0, 0, 0, 1, 0. You may include the 99 result even though now it is rated as 0.
    Depends on your values. If the max must be in the range [0..98] and all values are 99, the failover would be 0.

    Keep in mind that the request was made on a MAX. max of 0,0,0,1,99 excluding 99's, and 0,0,0,1,0 are the same - 1.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  8. #8
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,134
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    My bad, I thought this was in relation to http://www.sitepoint.com/forums/show...s-In-Form-Post. I got confused. If it were in relation, then my statement would still hold true, but if it isn't you are correct that 0,0,0,1,0 is the same as excluding the 99 and only having 0,0,0,1 in the range.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •