I have the following code:
[CODE=php]$cPath_new_a = $categories['categories_id']. ",";
$cPath_new_b = $cPath_new_a;
$cPath_new_c = rtrim($cPath_ne w_b , ',');
echo $cPath_new_c;
[/CODE]
$categories['categories_id'] pulls a sub category ID out of the database based on what main category the user is in. Let's say I am in a main category with 2 subcategories, 23 and 53. $categories['categories_id'] alone echos 2353. I want to make this into an array that contains 23 and 53.
I thought the best way to accomplish this would be to add a , to make the string 23,53, then remove the last , then use explode(); to convert the comma delimited string into an array. However rtrim/substr both are not working for me.Using rtrim (see code above) outputs 2353, I also get the same result using substr. Is there some way to convert $cPath_new_a into an actual string within the code (not a dynamic variable) then apply rtrim or substr? Or am I approaching this whole thing incorrectly?
I really appreciate any feedback.
[CODE=php]$cPath_new_a = $categories['categories_id']. ",";
$cPath_new_b = $cPath_new_a;
$cPath_new_c = rtrim($cPath_ne w_b , ',');
echo $cPath_new_c;
[/CODE]
$categories['categories_id'] pulls a sub category ID out of the database based on what main category the user is in. Let's say I am in a main category with 2 subcategories, 23 and 53. $categories['categories_id'] alone echos 2353. I want to make this into an array that contains 23 and 53.
I thought the best way to accomplish this would be to add a , to make the string 23,53, then remove the last , then use explode(); to convert the comma delimited string into an array. However rtrim/substr both are not working for me.Using rtrim (see code above) outputs 2353, I also get the same result using substr. Is there some way to convert $cPath_new_a into an actual string within the code (not a dynamic variable) then apply rtrim or substr? Or am I approaching this whole thing incorrectly?
I really appreciate any feedback.
Comment