note 51093 added to function.echo

From: Date: Sat, 19 Mar 2005 13:51:04 +0000
Subject: note 51093 added to function.echo
Groups: php.notes 
Request: Send a blank email to php-notes+get-86687@lists.php.net to get a copy of this message
Just found out some strange (at least to me) bahavior of echo when it is used with nested arrays. PHP5 with Apache2 for Win32 I use (wow, it's as if Yoda said that :) ) Here's the example: <?php // the array in question: $blah[0] = array(7, 5, 3, 1); // echo 'string'.$blah[0][2]; works fine: echo 'This is blah[0] - '.$blah[0]."<br />\n"; echo 'this is blah[0][2] - '.$blah[0][2]; ?> Output is: This is blah[0] - Array; this is blah[0][2] - 3 So far so good. However, when you echo it like this you get to the interesting part: <?php // echo "string $blah[0][2]"; doesn't recognize the nested array. echo "This is blah[0] - $blah[0]; "; echo "this is blah[0][2] - $blah[0][2]"; ?> Output: This is blah[0] - Array; this is blah[0][2] - Array[2] Here the 'Array[2]' part is what bothers me. I had a script I coudn't get working right for a while, and this seems to have been the problem. The '[2]' at the end is obviously interpreted as part of the string that includes the variable name. Hope that's of some help to somebody. Cheers, Emil Nachev ---- Manual Page -- http://www.php.net/manual/en/function.echo.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+51093 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+51093&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+51093&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+51093&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+51093&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+51093&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+51093&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#86687) next »