Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.