Jump to content

from "1_2_3" to "1, 1_2, 1_2_3"


stacyr

Recommended Posts

hello!

 

anyone know how you convert the string:

$currentcategory = "category1_sub1_sub2_sub3"

 

to this:

$categorytree = "category1.php : category1_sub1.php : category1_sub1_sub2.php : category1_sub1_sub2_sub3.php"

 

?

 

i.e. how could you go from "1_2_3" to "1 - 1_2 - 1_2_3" ?

 

 

Link to comment
https://forums.phpfreaks.com/topic/90411-from-1_2_3-to-1-1_2-1_2_3/
Share on other sites

try

<?php
$currentcategory = 'category1_sub1_sub2_sub3';
$currentcategory =explode('_', $currentcategory);
for($i = 1; $i < count($currentcategory); $i++) $currentcategory[$i] = $currentcategory[$i - 1].'_'.$currentcategory[$i];
$categorytree =implode('.php : ', $currentcategory).'.php';
echo $categorytree;
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.