I need some help with this array I can't figure out how can I create a multidimensional array according to some array values.
I have a normal array, let's say with the following dump output:
array(
[0] => ("id" => "421", "name" => "element 1", "TYPE" => "1")
[1] => ("id" => "422", "name" => "element 2", "TYPE" => "2")
[2] => ("id" => "423", "name" => "element 3", "TYPE" => "2")
[3] => ("id" => "424", "name" => "element 4","TYPE" => "1")
)
I need to create a multidimensional array according to "TYPE" key. if TYPE = 1 this array should contain all arrays which have "TYPE" == 2 until the next array will be found with the TYPE == 1 the output should be something like this:
array(
[421] => array(
"column" => array("id" => "421", "name" => "element 1", "TYPE" => "1"),
"subcolumns" => array(
[0] => ("id" => "422", "name" => "element 2", "TYPE" => "2"),
[1] => ("id" => "423", "name" => "element 3","TYPE" => "2")
)
)
[424] => array(
"column" => array("id" => "424", "name" => "element 4","TYPE" => "1"),
"subcolumns" => array()
)
)
Any ideas if I can accomplish this task with twig (it will be much better for me), if not, I am ok with PHP too. I have already tried to construct the HTML structure without changing the array but with no success.
I need to create columns and the "parent" should be the item with Type 1, all items with TYPE 2 should be childs of TYPE 1, in order to use jquery ui to sort them left and right.
Thank you!