How can I convert the following array: (Assume I don’t know how many depth of the array and key names)
$array = array(
'ycol'=>array('1'=>array( 'name1'=>array('data1',array('a','1'),'data3')),
'2'=>array('name2'=>array('data1',array('b','2'),'data3')),
'3'=>array('name3'=>array('data1',array('c','3'),'data3')),
'4'=>array('name4'=>array('data1',array('d','4'),'data3')),
'5'=>array('name5'=>array('data1',array('e','5'),'data3'))
);
into the following format: (Please show me how to use the recursive)
$array = array(
array('head'=>'name1','head1'=>'data1','o1'=>'a','o2'=>'1','head2'=>'data3'),
array('head'=>'name2','head1'=>'data1','o1'=>'b','o2'=>'2','head2'=>'data3'),
array('head'=>'name3','head1'=>'data1','o1'=>'c','o2'=>'3','head2'=>'data3'),
array('head'=>'name4','head1'=>'data1','o1'=>'d','o2'=>'4','head2'=>'data3'),
array('head'=>'name5','head1'=>'data1','o1'=>'e','o2'=>'5','head2'=>'data3')
);
I am new to PHP and need the help!
Thank you!
Assuming your syntax and depth is always the same, the above can be done messily as below.
There are cleaner ways to do it, but you have not provided anything you have tried to handle the recursion.