1

I've just been learning arrays, and so far it's going well :)
This is my current PHP code:

<?php
      $states = array ('MD' => 'Maryland', 'IL' => 'Illinois', 'MI' => 'Michigan');
      $provinces = array ('QC' => 'Quebec', 'AB' => 'Alberta');	
	  $abbr = array ('US' => $states, 'Canada' => $provinces);
      $japanesemotors = array ('ToyotaCamry' => '<img src="http://upload.wikimedia.org/wikipedia/commons/thumb/f/fe/2006_Toyota_Camry_%28ACV40R%29_Altise_01.jpg/800px-2006_Toyota_Camry_%28ACV40R%29_Altise_01.jpg">');
	  ?>
<?php
echo $abbr['US']['MI'];  ?>
<?
echo $abbr['Canada']['AB'];
?>
<?
echo $abbr['japanesemotors']['ToyotaCamry'];
?>

However, I can't get a newline in between the arrays, so it produces the following:

MichiganAlberta<IMAGE>

How do I get a new line to work in or in between the echo function?

Also, can you use the php include function in arrays like I used the HTML image function in my japanesemotors example above?

Thanks

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by nav33n
2

To get a new line, you should add a <br /> to your echo.
ie.,

<?php
echo $abbr['US']['MI']."<br />";  
?>
//or simply
<?php
echo $abbr['US']['MI'];  
echo "<br />";
?>

Also, can you use the php include function in arrays like I used the HTML image function in my japanesemotors example above?

That's a good one. I never did this (or even thought of having an include in an array).
But It doesn't work. Whenever you call the construct "include", it will start processing the 'included' file, ie., it will print if there is any print statement, or make the variables in the included file accessible to the 'base' file (the file where you are using include).
Here is a small example I tried out.

<?php
//include1.php
echo "From Include 1<br>";
?>
<?php
//include2.php
echo "From Include 2<br>";
?>
<?php
//include_in_array.php
$arr = array("a"=>include "include1.php", "b"=>include "include2.php" );
?>

There are 3 files, include1.php, include2.php and include_in_array.php . When you execute the file include_in_array.php , you will see 2 lines (From Include1 and From Include2) printed in the browser.
If you try printing $arr , it will print 1, which simply indicates that the file include1.php was included successfully.
So, the bottomline is, you can't include a file in an array.

Votes + Comments
include in a array..! really good one!!
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.