Unify Multidimensional Array in only 1 array in PHP

Asked

Viewed 215 times

0

Is it possible to transform a Multidimensional array into just 1 (one) array in php? What would the process be like to do this?

In the image below, I need to transform the array on the left side so that the records are equal to the right side, I tried with the array_merge but it doesn’t work, someone knows otherwise?

inserir a descrição da imagem aqui

  • 3

    It is not possible because the PHP does not accept a array with two or more equal indices.

  • And if I changed the name of the indexes so that I did not become equal, like id1, id2, id3, etc... It would be possible so?

  • What is the reason to unite the arrays? In my view, it will only be difficult to manipulate it.

  • @Jorgitodasilvapaiva Yes, it is possible, just use a foreach to traverse the first array and go creating a new array with the values.

  • The reason to join the arrays will be to join an array that will always return 4 rows of records from a database query to another array that will have the other data in just one row and unite everything to stay in just one line, is the idea clear? I tried to do this with foreach but it didn’t work.

  • @Valdeir Psr if you can demonstrate the structure of this foreach I thank you.

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.