Sort by value in multidimensional array I have a multidimensional array of house properties:

$array = array(
    array('apn' =&gt; 345345353, 'sqft' =&gt; 1121, 'address' =&gt; '12 Lincoln Ave.'),
    array('apn' =&gt; 345345351, 'sqft' =&gt; 1643, 'address' =&gt; '13 Lincoln Ave.'),
    array('apn' =&gt; 345345352, 'sqft' =&gt; 1222, 'address' =&gt; '14 Lincoln Ave.')
    array('apn' =&gt; 345345358, 'sqft' =&gt; 1226, 'address' =&gt; '6 Olark Ave.')
    array('apn' =&gt; 345345345, 'sqft' =&gt; 1200, 'address' =&gt; '323 Pacific Ave.'),
    array('apn' =&gt; 345345342, 'sqft' =&gt; 1421, 'address' =&gt; '324 Pacific Ave.'),
    array('apn' =&gt; 345345347, 'sqft' =&gt; 1093, 'address' =&gt; '328 Pacific Ave.'),
);


What I want to create from it is an array with just the lowest and highest address for each street. If a street has only one address then it shouldn't show up in the array. 

array('323 Pacific Ave.', '328 Pacific Ave.', '12 Lincoln Ave.', '14 Lincoln Ave.')


Currently I have the following function that works find but it is very verbose and I'm trying to figure out a simple way to sort by value in a multidimensional array. 

function minMaxAddress($data) {
    $addressRanges = array();
    $streets = array();
    $numProperties = count($data);
    $i = 0;
    foreach ($data as $key =&gt; $listing) {
        $address = $listing['address'];
        $street = getStreetName($address);
        if ($i == 0) {
          $addressRanges[] = $address;
        }
        else if ($street != end($streets)) {
          $addressRanges[] = $lastAddress;
          $addressRanges[] = $address;
        }
        if ($i == $numProperties - 1) {
            $addressRanges[] = $address;
        }
        $streets[] = $street;
        $lastAddress = $address;
        $i++;
    }
    $addressRanges = array_diff($addressRanges, array_diff_assoc($addressRanges, array_unique($addressRanges)));
    $addressRanges = array_values($addressRanges);
    return $addressRanges;
}
While this task can be written as a single loop over your data, it would involve unnecessarily convoluted conditionals and temporary variables which will likely be an irritation to future developers (that person might actually be you) that may need to read your code.

I respect your desire to keep things terse, but great code isn't just brief, it is easily comprehensible.  I feel that two loops will be the smartest approach.  In the first loop, create a grouping array with the street name as keys and push each number into its respective street's subarray.

Then filter the group array for qualifying data (2 or more numbers in a group), extract the highest and lowest number, then append the bookend numbers to the street name. 

Code: (Demo)

$array = [
    ['apn' =&gt; 345345353, 'sqft' =&gt; 1121, 'address' =&gt; '12 Lincoln Ave.'],
    ['apn' =&gt; 345345351, 'sqft' =&gt; 1643, 'address' =&gt; '13 Lincoln Ave.'],
    ['apn' =&gt; 345345352, 'sqft' =&gt; 1222, 'address' =&gt; '14 Lincoln Ave.'],
    ['apn' =&gt; 345345358, 'sqft' =&gt; 1226, 'address' =&gt; '6 Olark Ave.'],
    ['apn' =&gt; 345345345, 'sqft' =&gt; 1200, 'address' =&gt; '323 Pacific Ave.'],
    ['apn' =&gt; 345345342, 'sqft' =&gt; 1421, 'address' =&gt; '324 Pacific Ave.'],
    ['apn' =&gt; 345345347, 'sqft' =&gt; 1093, 'address' =&gt; '328 Pacific Ave.'],
];

foreach ($array as $row) {
    [$number, $street] = explode(' ', $row['address'], 2);
    $group[$street][] = $number;
}

$result = [];
foreach ($group as $street =&gt; $numbers) {
    if (sizeof($numbers) &gt; 1) {
        array_push($result, min($numbers) . ' ' . $street, max($numbers) . ' ' . $street);
    }
}

var_export($result);


Output:

array (
  0 =&gt; '12 Lincoln Ave.',
  1 =&gt; '14 Lincoln Ave.',
  2 =&gt; '323 Pacific Ave.',
  3 =&gt; '328 Pacific Ave.',
)