Find lowest value within session arrays using Min()


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!

$_SESSION[‘all’] is an array of arrays, so if you want to find the minimum car value, you have to do something like this;

$values = array();
foreach ($_SESSION['all'] as $car) {
    $values[] = $car['value'];

$cheapest = min($values);

Ofc. this will only give you the cheapest value, but not tell you which car that is the cheapest. If you need it’s itemNumber or model, then you probably have to do a check inside the loop, and manually store the id/model if it’s value is cheaper than the preceding array.

Thank you so much for the quick reply! You have really helped me out! I only needed the cheapest value so that is perfect.

Thanks again