racl101 + merging   9

PHP: array_reduce - Manual
This function is useful in situations where you need to deal with arrays of associative arrays with numeric keys and you want to merge them into one while preserving the numeric keys.

Like so, for example:

$arr1 = [ [ 1 => 'foo'], [3 => 'bar'], [7 => 'yo'], ..., [101 => 'dogg'] ];
$result = array_reduce($arr1, function ($carry, $item) { return $carry + $item; }, []);

This returns: [ 1 => 'foo', 3 => 'bar' .... 101 => 'dogg'];
php  manual  guide  reference  documentation  array_reduce  array  reduce  function  merging  tutorial  toread  tolearn  tounderstand 
march 2018 by racl101

Copy this bookmark:



description:


tags: