S
S
Stanislav2015-11-10 23:02:25
PHP
Stanislav, 2015-11-10 23:02:25

What is the most elegant way to make an unnamed array named in php, while the element name must be taken from the element itself, which is an array?

I have an array like this:

Array(
[0] => Array([id] => 341894 [name] => Дата экскурсии [values] => Array([0] => 1447372800) )
[1] => Array([id] => 341942 [name] => TripBook [values] => Array([0] => Array([value] => 0)) )
[2] => Array([id] => 341944 [name] => SAdvice [values] => Array([0] => Array([value] => 0)) )
[3] => Array([id] => 562286 [name] => Название экскурсии [values] => Array([0] => Array([value] => Тест)) )
)

It has a number of elements that changes from time to time, which are numbered in the code above, and these elements themselves are also arrays. These elements (arrays) have a named field id, and I would like that parent array to end up like this:
Array(
[id341894] => Array([id] => 341894 [name] => Дата экскурсии [values] => Array([0] => 1447372800) )
[id341942] => Array([id] => 341942 [name] => TripBook [values] => Array([0] => Array([value] => 0)) )
[id341944] => Array([id] => 341944 [name] => SAdvice [values] => Array([0] => Array([value] => 0)) )
[id562286] => Array([id] => 562286 [name] => Название экскурсии [values] => Array([0] => Array([value] => Тест)) )
)

That is, when unnamed elements would become named, moreover, they are named according to the field that they themselves contained.
The task for which this is all done is to extract the value from [values] => Array() from one or another element by a known id. It is clear that you can simply iterate over the array, but you want beauty.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question