imarockstar Posted June 24, 2009 Share Posted June 24, 2009 I am trying to print out an array ... here is my code $a = array($rows['gq_options']); foreach ($a as $v) { echo " $v<Br>"; } this is the output i am getting : Dr,Mr,Mrs,Miss,Ms what i need is there to be a beak after each value ... what am i missing here ... the array i have is coming from comma separated row in a database .. this is how i have it in the database Dr,Mr,Mrs,Miss,Ms do i hvae it in the DB wrong ? Link to comment https://forums.phpfreaks.com/topic/163558-help-me-with-an-array-issssuuue/ Share on other sites More sharing options...
ldougherty Posted June 24, 2009 Share Posted June 24, 2009 $a = array($rows['gq_options']); that is like saying $a is an array with the first value being an array itself. Instead of doing this try.. foreach ($rows['gq_options'] as $v) { echo " $v<Br>"; } Link to comment https://forums.phpfreaks.com/topic/163558-help-me-with-an-array-issssuuue/#findComment-862925 Share on other sites More sharing options...
imarockstar Posted June 24, 2009 Author Share Posted June 24, 2009 new code $a = array($rows['gq_options']); foreach ($rows['gq_options'] as $v) { echo " $v<Br>"; } and the error, lol : Warning: Invalid argument supplied for foreach() in /home/franklin/public_html/sites/questions/questions_general.php on line 25 line 25 is the foreach line .... Link to comment https://forums.phpfreaks.com/topic/163558-help-me-with-an-array-issssuuue/#findComment-862928 Share on other sites More sharing options...
ldougherty Posted June 24, 2009 Share Posted June 24, 2009 Hmm, without seeing the entire code its hard to decipher exactly what you are doing here.. try this and let me know the output.. $a = array($rows['gq_options']); print_r($rows['gq_options']); echo "<br><br>"; #foreach ($rows['gq_options'] as $v) { # echo " $v<Br>"; #} Link to comment https://forums.phpfreaks.com/topic/163558-help-me-with-an-array-issssuuue/#findComment-862931 Share on other sites More sharing options...
imarockstar Posted June 24, 2009 Author Share Posted June 24, 2009 this is the output : Dr,Mr,Mrs,Miss,Ms which is just how i have it in the database .. Link to comment https://forums.phpfreaks.com/topic/163558-help-me-with-an-array-issssuuue/#findComment-862934 Share on other sites More sharing options...
ldougherty Posted June 24, 2009 Share Posted June 24, 2009 print_r would not have outputted it like that.. can you run the code and show the full output so we can see the array itself? Link to comment https://forums.phpfreaks.com/topic/163558-help-me-with-an-array-issssuuue/#findComment-862936 Share on other sites More sharing options...
imarockstar Posted June 24, 2009 Author Share Posted June 24, 2009 here is the link ... http://franklinspirko.com/sites/questions/questions_general.php Link to comment https://forums.phpfreaks.com/topic/163558-help-me-with-an-array-issssuuue/#findComment-862942 Share on other sites More sharing options...
imarockstar Posted June 24, 2009 Author Share Posted June 24, 2009 this is how it is in the DB .. Dr,Mr,Mrs,Miss,Ms Link to comment https://forums.phpfreaks.com/topic/163558-help-me-with-an-array-issssuuue/#findComment-862944 Share on other sites More sharing options...
aggrav8d Posted June 24, 2009 Share Posted June 24, 2009 echo implode(', ',$rows['gq_options']); ? Link to comment https://forums.phpfreaks.com/topic/163558-help-me-with-an-array-issssuuue/#findComment-862950 Share on other sites More sharing options...
Andy-H Posted June 24, 2009 Share Posted June 24, 2009 $a = explode(',', $rows['gq_options']); foreach ($a as $v) { echo " " . $v . "<br >\n"; } Link to comment https://forums.phpfreaks.com/topic/163558-help-me-with-an-array-issssuuue/#findComment-862981 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.