Jump to content

Simple Echo Spacing Question


Foser

Recommended Posts

Hello well I've been learning php for around a day now and got to arrays which i found quite nice, better than normal statements.

Although I have problem with echo spacing also with everything else. here is my code.

 

<?php
$bakery = array(  
"Cherry" => array("5.00" , "six pieces"),
"Apple" => array("3.00" , "two pieces"),
);

echo "The Cherry costs".$backery[Cherry][0]."for". $bakery[Cherry][1];
echo "The Apple costs". $backery[Apple][0] ."for". $bakery[Apple][1];
?>

 

 

 

The output of this is:

The Cherry costsforsix piecesThe Apple costsfortwo pieces

 

how can i space the things? so it looks nice, and how to do so its one bellow each other....

 

Thanks

Link to comment
Share on other sites

<?php
echo "The Cherry costs " . $backery['Cherry'][0] . " for " . $bakery['Cherry'][1];
echo "The Apple costs " . $backery['Apple'][0] ." for " . $bakery['Apple'][1];

 

Just add spaces like above.

 

A side note, use single or double quotes around array indexes. IE Cherry and Apple, if you do not you have a chance of a notice of call to undefined constant. It is just proper PHP programming and tends to be more efficient.

Link to comment
Share on other sites

<?php
echo "The Cherry costs " . $backery['Cherry'][0] . " for " . $bakery['Cherry'][1];
echo "The Apple costs " . $backery['Apple'][0] ." for " . $bakery['Apple'][1];

 

Just add spaces like above.

 

A side note, use single or double quotes around array indexes. IE Cherry and Apple, if you do not you have a chance of a notice of call to undefined constant. It is just proper PHP programming and tends to be more efficient.

 

 

thanks!

 

 

also the first arrays in both echos don't show... why is that?

Link to comment
Share on other sites

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.