Bu durumda bana yardımcı olun. Ben bir dizi var, ve ben gibi, yeni bir tane yapmak istiyorum
array[0][id] = 1
array[0][parent_id] = null
array[0][order_id] = 1
array[1][id] = 2
array[1][parent_id] = null
array[1][order_id] = 2
etc.
Benim şu anki dizi bu gibi:
Array
(
[list] => Array // if the (array's name = `list`) the array[#][parent_id] = null
(
[0] => 1 // the key of the array (`[0]` in this case) is the array[#][order_id]
[1] => 2 // the value of the array (`2` in this case) is the array[#][id]
[2] => 5
)
[list_2] => Array // else the array[#][parent_id] = the number value after the _
(
[0] => 3
[1] => 4
)
[list_5] => Array
(
[0] => 6
)
)
A good solution based on Habax's script:
$new = array();
$n=0;
foreach($old as $key=>$item){
for ($i = 1; $i <= count($item); $i++) {
if($key=='list')$new[$n]['parent_id']=null;
else {
$tmp = explode('_', $key);
$new[$n]['parent_id']=$tmp[1];
}
$new[$n]['order_id']=$i;
$new[$n]['id']=$item[$i-1];
$n++;
}
}
}
Good to arrange nested sortables, like: http://www.b-hind.eu/jquery/ strong>