M
M
miron2582018-09-12 17:57:07
PHP
miron258, 2018-09-12 17:57:07

How to convert an array to another form?

There is a tree-like array with a menu of this kind demo.maika-cool.ru in the children cell to contain all its child elements. You need to write a function for it that will convert it to the next array.
/*************** THE ARRAY WHICH REQUIRES A CONVERSION CAN BE VIEWED BY CLICKING THE LINK ABOVE ************** PIECE OF EXAMPLE /
Array
(
[0] => Array
(
[id] => 1
[class] => vm-visible-md vm-visible-lg
[depth] => 1
[title] => Create
[action] => Array
(
[href] => /constructor
[ target] =>
)
[is_new] =>
[children] => Array
(
[0] => Array
(
[id] => 2
[class] => vm-visible-xs vm-visible-sm vm-visible-md vm-visible-lg
[depth] => 2
[title] => Men
[action] => Array
(
[href] => /catalog/view/manwear?sort=sell
[target] =>
)
[is_new] =>
[children] => Array
/************* WHAT I WANT TO SEE IN THE NEW ARRAY OUTPUT ********************/
array(
' id'=>1, //ID menu
'title'=>'value of cell title',
'class'=> 'Value of cell class',
'depth'=> 'Possible nesting level although not needed',
'action ' => 'action cell value further href',
'parent_id' => 5 //parent ID if if yes if not then 0);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
float64, 2018-10-14
@float64

What exactly is the problem? If it is difficult to deal with the chain of transformations - try using fractal - the task will become easier to solve: fractal.thephpleague.com

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question