phpsub-arrayarray-unique

PHP Array_unique


Is it possible to remove sub arrays, if the array item at position 0 of that sub array matches subsequent items?

For example;

Array ( [0] => Array ( [0] => 1234 [1] => XX000 ) 
        [1] => Array ( [0] => 1234 [1] => XX001 ) 
        [2] => Array ( [0] => 1234 [1] => XX002 ) 
      )

Would be adjusted to output;

Array ( [0] => Array ( [0] => 1234 [1] => XX000 ) )

Solution

  • Always the way, I've found out the solution after posting this ($query being the multi-dimensional array);

    $newArr = array();
    
    foreach ($query as $val) {
        $newArr[$val[0]] = $val;    
    }
    
    $query = array_values($newArr);