PHP shortest/longest string length in array

Viewed 33848

I have an array like this

$data = array(
    "163",
    "630",
    "43",
    "924",
    "4",
    "54"
);

How can I select the smallest and largest values from it according to string length NOT number value. (for this example it is 1 (smallest) and 3 (largest).

6 Answers

For completion, here is a one-liner for maximum and minimum:

$maximum = max(array_map('strlen', $array));
$minimum = min(array_map('strlen', $array));
Related