Voting

: nine minus four?
(Example: nine)

The Note You're Voting On

oliver dot eglseder at co-stack dot com
14 days ago
array_column is the only function out of array_values, array_merge, array_slice and array_column that does de-reference values. Also, it works recursive!

<?php
$values
= [];
$values['a'] = [];
$values['a']['b'] = 'foo';

$references = [];
$references['a'] = &$values['a'];

$copyColumn = array_combine(array_keys($references), array_column($references, null));

$values['a']['b'] = 'baz';

echo
$copyColumn['a']['b'] . PHP_EOL; // foo
echo $references['a']['b'] . PHP_EOL; // baz
?>

If you want to preserve the keys you can use

<?php
$dereferenced
= array_combine(array_keys($references), array_column($references, null))
?>

<< Back to user notes page

To Top