oddball25 Posted February 17, 2011 Share Posted February 17, 2011 Hi I am having trouble using the min() function to find the lowest value within my session arrays. On my site i have the following car values saved into my $car array: $car = array( "itemNumber" => $itemNumber, "Model" => $Model, "EngineSize" => $EngineSize, "Colour" => $Colour, "Value" => $Value, ); I then store each $item array into a $_SESSION['all'] as below: if (isset($_SESSION['all'])) { $_SESSION['all'][$number] = $car; } else { $_SESSION['all'] = array($number => $car); } Now i need to find the lowest Value of all the cars that the user may add. I have been using the min() function to try and do this with the following code but it gives me the error: Wrong parameter count for min()..... $cheapest = min($car['Value']); Am i on the right tracks or is this not possible? If anyone could shed some light on how i can get this to work, would be very much appreciated! Link to comment https://forums.phpfreaks.com/topic/227977-find-lowest-value-within-session-arrays-using-min/ Share on other sites More sharing options...
oddball25 Posted February 17, 2011 Author Share Posted February 17, 2011 Solved with: $values = array(); foreach ($_SESSION['all'] as $car) { $values[] = $car['value']; } $cheapest = min($values); Link to comment https://forums.phpfreaks.com/topic/227977-find-lowest-value-within-session-arrays-using-min/#findComment-1175583 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.