Jump to content

Just Started: Arrays question


dani0157

Recommended Posts

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

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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.