#6414 [Csd]: foreach() doesn't accept string for an argument

From: Date: Mon, 17 Mar 2003 08:12:49 +0000
Subject: #6414 [Csd]: foreach() doesn't accept string for an argument
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-35726@lists.php.net to get a copy of this message
ID: 6414 Updated by: helly@php.net Reported By: cynic at mail dot cz Status: Closed -Bug Type: Scripting Engine problem +Bug Type: Feature/Change Request -Operating System: NT 4.0 SP5 +Operating System: ANY -PHP Version: 4.0 Latest CVS (29/08/2000) +PHP Version: 5.0 New Comment: This is a thing to think about: Since strings are NOT accepted as foreach input we could add that by delivering eash single character. >php -r '$a="abc";foreach($a as $i => $c) echo "$i:$c\n";' 0:a 1:b 2:c Previous Comments: ------------------------------------------------------------------------ [2003-03-17 01:46:32] yuki_yew78 at yahoo dot com me too ------------------------------------------------------------------------ [2000-08-29 11:12:32] jmoore@php.net You need to cast your string as an array.. <?php $b = "abcdefgh" ; $b = (array)$b; foreach( $b as $y ) { echo $y ; }; ?> Works. James ------------------------------------------------------------------------ [2000-08-29 10:47:05] cynic at mail dot cz $b = "abcdefgh" ; foreach( $b as $y ) { echo $y ; } ; Warning: Invalid argument supplied for foreach() ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=6414&edit=1

« previous php.bugs (#35726) next »