jay_bo Posted March 21, 2010 Share Posted March 21, 2010 I have a variable that i want to spilit up but i will need it in a loop as i don't know how many i would need to spilit it up by....Ive searched around on the internet but i cant really make sense, anybody willing to help? Link to comment https://forums.phpfreaks.com/topic/196014-splilting-a-variable/ Share on other sites More sharing options...
Hybride Posted March 21, 2010 Share Posted March 21, 2010 You can try figuring out how you want to split up the variable - is it with spaces, some character (+,-,=,!,etc). If you have any code to show, we might be able to help, but your request is extremely vague. Try looking up: Str_Split; if you want to use regular expressions, there's preg_split; or if you use an array, you can try explode. Link to comment https://forums.phpfreaks.com/topic/196014-splilting-a-variable/#findComment-1029594 Share on other sites More sharing options...
jay_bo Posted March 21, 2010 Author Share Posted March 21, 2010 Yea i want to splilt it up by spaces..... this is my code if(is_array($_SESSION['cart'])){ echo '<tr bgcolor="#FFFFFF" style="font-weight:bold; color:#FFF; background-image:url(media/images/site/shopping_table_bg.jpg); background-repeat:repeat;""><td>Products</td><td>Name</td><td>Price</td><td>Qty</td><td>Amount</td><td>Options</td></tr>'; $max=count($_SESSION['cart']); for($i=0;$i<$max;$i++){ $pid=$_SESSION['cart'][$i]['productid']; $q=$_SESSION['cart'][$i]['qty']; $pname=get_product_name($pid); if($q==0) continue; I'm wanting to spilit up $q so that i can add up all the numbers in that variable... when i echo the variable it displays 1 1 4 Link to comment https://forums.phpfreaks.com/topic/196014-splilting-a-variable/#findComment-1029596 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.