3v4l.org

run code in 300+ PHP versions simultaneously
<?php $json = <<<'JSON' [ { "code": "AF", "total": 1 }, { "code": "DZ", "total": 1 }, { "code": "AS", "total": 2 } ] JSON; $array = json_decode($json, true); function compoundArray(Array $array, $key, $value) { return array_column($array, $key, $value); } var_dump(compoundArray($array, 'total', 'code'));

preferences:
26.66 ms | 406 KiB | 5 Q