find the smallest value in a map in php

To find the smallest value in a PHP map (associative array), you can use the PHP min() function with the array_values() method. Here's an example:

main.php
$map = array(
  "apple" => 5,
  "banana" => 3,
  "pear" => 2,
  "orange" => 4
);

$min_value = min(array_values($map));
echo "The smallest value in the map is: " . $min_value; // Output: The smallest value in the map is: 2
223 chars
10 lines

In this example, we first define an associative array called $map. Then we use the min() function with array_values($map) as the argument to get the smallest value in the map. Finally, we output the result using echo.

related categories

gistlibby LogSnag