arrays - Merge subarrays of different lengths PHP -
i have dynamically built array looks so:
array(2) { [0]=> array(2) { [0]=> array(1) { ["rhid"]=> string(6) "169135" } [1]=> array(1) { ["rhid"]=> string(6) "168917" } } [1]=> array(2) { [0]=> array(1) { ["rhid"]=> string(6) "172168" } [1]=> array(123) { ["rhid"]=> string(6) "171169" } [3]=> array(123) { ["rhid"]=> string(6) "171129" } [3]=> array(1) { [0]=> array(1) { ["rhid"]=> string(6) "172768" } }
but instead combine subarrays so:
array(1) { [0]=> array(4) { [0]=> array(1) { ["rhid"]=> string(6) "169135" } [1]=> array(1) { ["rhid"]=> string(6) "168917" } [2]=> array(1) { ["rhid"]=> string(6) "172168" } [3]=> array(123) { ["rhid"]=> string(6) "171169" } [4]=> array(1) { ["rhid"]=> string(6) "172768" } } }
note never know how many subarrays have. 1 or 2 or 7. excuse me if forgot bracked or editing in notepad.
foreach ($array $subarray) { foreach ($subarray $entry) { $newarray[] = $entry; } }
it's easy that.
Comments
Post a Comment