almightyegg Posted April 3, 2008 Share Posted April 3, 2008 I have this script: if($crops[start2] > $gap5start){ $select2 = "$crops[start2]"; echo "<br><br><br>$select 2<br><br><br>"; } if($crops[start3] > $gap5start){ $select3 = "$crops[start3]"; echo "<br><br><br>$select 3<br><br><br>"; } if($crops[start5] > $gap5start){ $select5 = "$crops[start5]"; } Then I want to put the $selectX variables into a min() function. As you probably know you need a comma and a space between eache vairable in the min() func. So I was wondering if there was a function that I could use to stitch these together into one variable: min($variable); The problem is that the values aren't always set, and if they aren't set then you don't need a comma space Hope that made sense Quote Link to comment Share on other sites More sharing options...
rhodesa Posted April 3, 2008 Share Posted April 3, 2008 min($array) will return the lowest number in the array Quote Link to comment Share on other sites More sharing options...
almightyegg Posted April 3, 2008 Author Share Posted April 3, 2008 Didn't work.. $select = array($select1, $select2, $select3, $select5); $gap5fin = min($select); $gap5fin is blank... Unless it's counting the unset variables as 0s? Which would be lower Quote Link to comment Share on other sites More sharing options...
almightyegg Posted April 3, 2008 Author Share Posted April 3, 2008 I managed to sort that but I have a similar issue elsewhere: $gaps = array($gap1start, $gap2start, $gap3start, $gap4start, $gap5start, $gap6start); $count = count($gaps); echo "$count"; I was hoping that would count the variables that are set. In my case for testing $gap1start, $gap2start, $gap4start and $gap4start are all empty, so I want it to count 2 (as only 2 of the array actually have any value) Is there another way? Quote Link to comment Share on other sites More sharing options...
stuffradio Posted April 3, 2008 Share Posted April 3, 2008 What happens if you go foreach ($gaps as $arrvalues) { if (isset($arrvalues)) { echo "$count"; } } Does that work for you? Quote Link to comment Share on other sites More sharing options...
rhodesa Posted April 4, 2008 Share Posted April 4, 2008 I managed to sort that but I have a similar issue elsewhere: $gaps = array($gap1start, $gap2start, $gap3start, $gap4start, $gap5start, $gap6start); $count = count($gaps); echo "$count"; I was hoping that would count the variables that are set. In my case for testing $gap1start, $gap2start, $gap4start and $gap4start are all empty, so I want it to count 2 (as only 2 of the array actually have any value) Is there another way? You could go through the array and remove empty values, but it seems there would be a better way using an array from the beginning. So, store everything in $gaps from the start, but if you don't use #2, just don't set the value for #2. So you're array would end up looking like: array( 1 => 'value 1', 3 => 'value 3', 4 => 'value 4', ) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.