dani0157 Posted March 26, 2010 Share Posted March 26, 2010 I just started learning PHP and i am currently learning Arrays. Question: <?php $countries=array("The Netherlands","Germany","Australia","Bulgaria"); echo "I have visited and lived in" . $countries[3] . "and" . $countries[0]; ?> When i display this in a browser it dont leave any space between the words at the end. It is: I have visited and lived inBulgariaandThe Netherlands And it must be: I have visited and lived in Bulgaria and The Netherlands Link to comment https://forums.phpfreaks.com/topic/196650-just-started-arrays-question/ Share on other sites More sharing options...
mikesta707 Posted March 26, 2010 Share Posted March 26, 2010 this isn't really an array problem, more a string problem. if you want spaces, then insert them echo "I have visited and lived in " . $countries[3] . " and " . $countries[0]; you have to realize that whatever you type into the script, its all the PHP knows or cares about. it won't add in spaces unless you tell it too, and you always need to be conscious of what exactly you are telling the program to do. Link to comment https://forums.phpfreaks.com/topic/196650-just-started-arrays-question/#findComment-1032473 Share on other sites More sharing options...
dani0157 Posted March 26, 2010 Author Share Posted March 26, 2010 this isn't really an array problem, more a string problem. if you want spaces, then insert them echo "I have visited and lived in " . $countries[3] . " and " . $countries[0]; you have to realize that whatever you type into the script, its all the PHP knows or cares about. it won't add in spaces unless you tell it too, and you always need to be conscious of what exactly you are telling the program to do. Thanks for the help and advice. Link to comment https://forums.phpfreaks.com/topic/196650-just-started-arrays-question/#findComment-1032476 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.