Foser Posted May 10, 2007 Share Posted May 10, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/50798-simple-echo-spacing-question/ Share on other sites More sharing options...
taith Posted May 10, 2007 Share Posted May 10, 2007 echo "The Cherry costs".$backery[Cherry][0]."for". $bakery[Cherry][1]."<br>"; echo "The Apple costs". $backery[Apple][0] ."for". $bakery[Apple][1]."<br>"; Quote Link to comment https://forums.phpfreaks.com/topic/50798-simple-echo-spacing-question/#findComment-249780 Share on other sites More sharing options...
per1os Posted May 10, 2007 Share Posted May 10, 2007 <?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. Quote Link to comment https://forums.phpfreaks.com/topic/50798-simple-echo-spacing-question/#findComment-249784 Share on other sites More sharing options...
Foser Posted May 10, 2007 Author Share Posted May 10, 2007 <?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? Quote Link to comment https://forums.phpfreaks.com/topic/50798-simple-echo-spacing-question/#findComment-249789 Share on other sites More sharing options...
ph2007 Posted May 10, 2007 Share Posted May 10, 2007 It's because you have a typo when referencing the array. Your code is attempting to access $backery['Cherry'][0], instead of $bakery['Cherry'][0]. See the extra 'c'? Quote Link to comment https://forums.phpfreaks.com/topic/50798-simple-echo-spacing-question/#findComment-250027 Share on other sites More sharing options...
Foser Posted May 11, 2007 Author Share Posted May 11, 2007 ah ok, thanks mate. Solved it. Quote Link to comment https://forums.phpfreaks.com/topic/50798-simple-echo-spacing-question/#findComment-250251 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.