RE: [PHP-DEV] Re: PHP 4.0 Bug #6414 Updated: foreach() doesn't accept string for an argument

From: Date: Tue, 29 Aug 2000 16:42:21 +0000
Subject: RE: [PHP-DEV] Re: PHP 4.0 Bug #6414 Updated: foreach() doesn't accept string for an argument
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-31091@lists.php.net to get a copy of this message
> No, it doesn't: > > $b = "abcdef" ; > $b = (array)$b ; > $x = 0 ; > foreach( $b as $c ) > { > echo "$x: $c<br>" ; > $x++ ; > } ; > echo "size: " . sizeof( $b ) ; > > this outputs: > > 0: abcdef > size: 1 OK this might well be true I didnt test it.. But the manual does state foreach needs array inputs not string inputs, so it is not suprising that PHP complains when you pass it a string, I reliase that strings/arrays can be treated similarly, I suggest you convert it to an array using some loop.. Maybe somthing like: for($i=0;$i<strlen($b);$i++) { $b_array[] = $b[$i]; /* You might need $b_array = substr($b,$i,1); instead here... */ } Im sure Developers will correct me But I do not think at anypoint the construct was meant to work like this with strings and thus this is not a bug. James

« previous php.dev (#31091) next »