Hello, i need some help because i am struggling to accomplish what should be a simple task. i have no idea why this is becoming difficult. i’m unable to grasp the logic here.
i have a virtual path that i need to explode so i can use the values for various reasons. I have done this and it is working. However, i need the full path to be used to create a link. i also need the path to be subtracted to create other links. the links are virtual directories, thus i need paths to be like so:
../
../../
../../../
edit: the links are structured as above but the $path is backward: 3,2,1
i cannot figure out how to loop over the exploded path and link an imploded path minus the current path. i am thinking that i need a counter here, yes?
so to paint the picture more clear:
$path = 'Animalia/Arthropoda/Insecta';
$newpath = explode("/", $path);
$currentpage = array_pop($newpath);
//so newpath is now Animalia, Arthropoda, which are links as ../ and ../../
foreach ($newpath as $key=>$value) {
//now i can use these components for translation, content, images etc.
}
now i want to build a new form with links to previous pages
so the count needs to be backward as 3, 2, 1 because my links are off.
i need to loop the path from 2 to 3 not from 3 to 2.
here is code that works but it is backward 3-to-2 because of array pop.
$link = implode("/", $newpath);
foreach ($newpath as $key=>$value) {
if ($key < 1) {
${value} = csrfToken($value);
} else {
${value} = csrfToken($link);
$newlink = explode("/", $link);
array_pop($newlink);
$link = implode("/", $newlink);
}
}