PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
andym01480
Forum Contributor
Posts: 390 Joined: Wed Apr 19, 2006 5:01 pm
Post
by andym01480 » Tue Jun 06, 2006 3:33 pm
I can't fathom out echoing an array!
Here's my code to try and understand it all
Code: Select all
print_r ($matches);
echo "<p>$matches[0][2]<p>$matches[1][2]<p>";
$first=$matches[1];
echo "0=$first[0]<p>1=$first[1]<p>2=$first[2]";
which produces
Code: Select all
Array ( [0] => Array ( [0] => Wed - Jun 07 -- Thu - Jun 08
[1] => [2] => Wed - Jun 07 -- Thu - Jun 08 [3] => [4] => Wed - Jun 07 -- Thu - Jun 08 [5] =>
) [1] => Array ( [0] => Sun - Jun 11
[1] => [2] => Sun - Jun 11 [3] => Sun - Jun 11 [4] => [5] =>
) )
Array[2]
Array[2]
0=Sun - Jun 11
1=
2=Sun - Jun 11
why doesn't
produce
?
PrObLeM
Forum Contributor
Posts: 418 Joined: Sun Mar 07, 2004 2:30 pm
Location: Mesa, AZ
Contact:
Post
by PrObLeM » Tue Jun 06, 2006 3:36 pm
try
Code: Select all
echo "<p>" . $matches[0][2] . "<p>" . $matches[1][2] . "<p>";
andym01480
Forum Contributor
Posts: 390 Joined: Wed Apr 19, 2006 5:01 pm
Post
by andym01480 » Tue Jun 06, 2006 3:42 pm
Grazie Multi.
Why can't an multidimensional array be echoed within double quotes?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Jun 06, 2006 3:53 pm
Only one level of elements is understood as it becomes a string immediately after being looked up.
Christopher
Site Administrator
Posts: 13596 Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US
Post
by Christopher » Tue Jun 06, 2006 3:53 pm
andym01480 wrote: Why can't an multidimensional array be echoed within double quotes?
It can, you just need to help the parser out a little (same with object properties):
Code: Select all
echo "<p>{$matches[0][2]}<p>{$matches[1][2]}<p>";
(#10850)