Jnerocorp Posted December 6, 2009 Share Posted December 6, 2009 Hello, its supposed to take the $output and change it original = john,18,Cancer After = 'john', '18', 'Cancer' but right now it does this: original = john,18,Cancer After = 'Cancer' this is my code so far: <?php $output = "john,18,Cancer"; echo "Original Output: $output <br>"; $explode = explode(",", $output); $wordChunks = explode(",", $output); for($i = 0; $i < count($wordChunks); $i++){ $newoutput = "'$wordChunks[$i]', "; } echo "New Output: " . $newoutput . "<br>"; echo "<br>"; $removecomma = substr_replace($newoutput, "", -2); echo "Remove Final Comma: $removecomma"; echo "<br>"; ?> thanks for any help -John Link to comment https://forums.phpfreaks.com/topic/184173-ghelp-getting-all-pieces-of-an-exploded-array/ Share on other sites More sharing options...
mrMarcus Posted December 6, 2009 Share Posted December 6, 2009 change: for($i = 0; $i < count($wordChunks); $i++){ $newoutput = "'$wordChunks[$i]', "; } to: for($i = 0; $i < count($wordChunks); $i++){ $newoutput .= "'$wordChunks[$i]', "; } notice the .= to concatenate the string. right now, you just keep resetting the variable $newoutput which is why you're only getting one value in the output. Link to comment https://forums.phpfreaks.com/topic/184173-ghelp-getting-all-pieces-of-an-exploded-array/#findComment-972343 Share on other sites More sharing options...
PFMaBiSmAd Posted December 6, 2009 Share Posted December 6, 2009 Or you can just do this a simple way - http://www.phpfreaks.com/forums/index.php/topic,279649.msg1324475.html#msg1324475 Link to comment https://forums.phpfreaks.com/topic/184173-ghelp-getting-all-pieces-of-an-exploded-array/#findComment-972348 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.