note 10710 added to foreach

From: Date: Thu, 18 Jan 2001 18:19:05 +0000
Subject: note 10710 added to foreach
Groups: php.notes 
Request: Send a blank email to php-notes+get-9930@lists.php.net to get a copy of this message
Note that you cannot use a string as an argument for foreach, even though you can access individual characters in a string LIKE a zero-based array. So instead of using foreach, try: $str='This is a string'; $x=0; while($str[$x]!=''){ echo $str[$x].'<br>'; $x++; } /* This will output T h i s i s a s t r i n g */ http://www.php.net/manual/en/control-structures.foreach.php

« previous php.notes (#9930) next »