note 10710 modified in control-structures.foreach by irc-html

From: Date: Wed, 16 Jan 2002 17:07:32 +0000
Subject: note 10710 modified in control-structures.foreach by irc-html
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-24931@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 */ --was-- 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 (#24931) next »