Forum Moderators: coopster
$string = 'template[0]=1&template[0][0]=2&template[0][1]=3&template[0][1][0]=5&template[0][1][1]=7&template[0][1][2]=6&template[0][1][3]=8&template[0][2]=4';
That string holds information about each placeholder of the website. BTW, a specific placeholder can be the parent of another placeholder, and all placeholders that are nested in a parent-placeholder have an specific order (starting form 0).
If I do this <?$arr = explode('&',$string)?>, i'll get this:
$arr[0] = "template[0]=7"
$arr[1] = "template[1]=5"
$arr[2] = "template[2]=1"
$arr[3] = "template[2][0]=2"
$arr[4] = "template[2][0][0]=6"
$arr[5] = "template[2][1]=3"
$arr[6] = "template[2][2]=8"
$arr[7] = "template[3]=4"
The placeholder's ID's are only contained after the "=" .. the pseudo-array in the string only contains ordered information of a nested order structure.
I need a way to manipulate that string so i know the placeholder's parent and order.
For example, it would be great to get something like this as a result:
# Page
$placeholder[1] = array(0,2);
# Sidebar
$placeholder[2] = array(1,0);
...
# Footer
$placeholder[4] = array(0,3);
...you get the point
In other words:
$placeholder[X] = array($parent,$order);
WHERE:
X = ID of placeholder
$parent = ID of placeholder's parent
$order = order of placeholder relative to other placeholders nested in the same parent
Any ideas on that?
Salute,
Andres S.
foreach(explode('&',str_replace('plantilla','','plantilla[0]=1&plantilla[0][0]=2&plantilla[0][1]=3&plantilla[0][1][0]=5&plantilla[0][1][1]=6&plantilla[0][1][2]=7&plantilla[0][1][3]=8&plantilla[1]=4')) as $id) {
$item = explode('=',$id);
$items[$item[1]] = $item[0];
}
foreach($items as $k=>$item) {
$padre = substr($item,0,strrpos($item,'['));
$orden = substr($item,strrpos($item,'[')+1,strrpos($item,']')-strrpos($item,'[')-1);
$placeholders[$k] = array($padre,$orden);
}