array_filter :
$bb = array_filter($aa, function($item) {
static $tmp = array();
if ($filter = !in_array($item['Oil'], $tmp)) {
$tmp[] = $item['Oil'];
}
return $filter;
});
This uses a static variable inside the function to "remember" the oil returned. This works because $ tmp is only used during array_filter execution. If you include this in a function and call it several times, for example, $ tmp will always be an empty array for the first call to the function provided by array_filter.
The second task, sorting, can be done using usort with a custom sorting function:
usort($bb, function($a, $b) {
return ($a['Spark Plugs'] > $b['Spark Plugs']
? 1
: -1);
});
source
share