I have this nested array
$lists = [
[
{"id": 1, "name": one},
{"id": 2, "name": two},
{"id": 3, "name": three},
],
[
{"id": 4, "name": four},
{"id": 5, "name": five},
{"id": 6, "name": six},
]
]
What should i do to make this array into one like this.
[
{"id": 1, "name": one},
{"id": 2, "name": two},
{"id": 3, "name": three},
{"id": 4, "name": four},
{"id": 5, "name": five},
{"id": 6, "name": six},
]
I tried array_merge using this code
$numbers =[];
foreach ($lists as $list) {
$numbers = array_merge($numbers, $list);
}
But it didn't work. It says that argument #2 is not an array.
numbersyou're referring to? I can't see it in the arrays you've posted? You should also clarify what "didn't work" means. Wrong result? Errors?json_encode(array_merge(...json_decode($json, true)))- sandbox.onlinephpfunctions.com/code/…$listsis invalid.