Input array $items:
Array
(
[0] => Array
(
[id] => 2
)
[1] => Array
(
[id] => 5
)
)
Result of print_r(foo($items))
Array
(
[2] => 1
[5] => 1
)
Function foo()
function foo($items)
{
$result = array();
foreach($items => $array)
{
$result[$array['id']] = TRUE;
}
return $result;
}
How can I simply write this array transformation with standards PHP functions, like array_flip() or something else. Is it possible?
Using a built in PHP function would only introduce the unnecessary overhead of additional function calls. What you have written is already an efficient method for creating the desired output from the given input.
I would recommend using your custom function if possible.