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 Quote 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. Quote 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. Quote Link to comment https://forums.phpfreaks.com/topic/196650-just-started-arrays-question/#findComment-1032476 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.