I have an object as below,
{"metaData":[{"name":"a"},{"name":"b"}],"rows":[[1,2],[3,4],[5,6]]}
I would like to change it to
[["a"=>1,"b"=>2],["a"=>4,"b"=>5],["a"=>5,"b"=>6]]
Is there any faster one liner that can convert this without going thru a loop in Laravel ?
You can get the keys with
array_column
, then maparray_combine
over the rows.You could make it a one-liner like this, but it's more difficult to read, and it will call
array_column
for every row instead of just once.You need to be sure that each row is the same size as the metadata array or
array_combine
will fail. Based on the appearance of your object, it looks like this would probably always be true, but it's important to note.