#20893 [Opn]: Strings as Arrays...
| From: | davey at its-explosive dot net | Date: | Mon, 09 Dec 2002 02:57:52 +0000 |
| Subject: | #20893 [Opn]: Strings as Arrays... | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-27112@lists.php.net to get a copy of this message | ||
ID: 20893
User updated by: davey@its-explosive.net
Reported By: davey@its-explosive.net
Status: Open
Bug Type: Feature/Change Request
Operating System: All
PHP Version: 4.3.0RC2
New Comment:
small code correction:
$string = "foo";
foreach ($string as $i) {
echo $i ."<br />\n";
}
Previous Comments:
------------------------------------------------------------------------
[2002-12-08 20:56:13] davey@its-explosive.net
This is probably a strange feature request, but I think it should be
given a lot of thought, if it has not done so already.
The request is this:
strings should be treated as arrays of characters (which they are) when
given as the arguement for functions which work on arrays.
so for example:
function foo ($chr) {
echo $chr . "<br />\n";
}
$string = "bar";
array_walk($string,foo); would give the result:
b
a
r
Also, to be able to do this with strings:
$string = "fo";
$string{} = "o";
so that
$string == "foo" == TRUE
Also, another thing that comes up often, is when trying to do this:
$string = "foo";
foreach ($string as $i) {
echo $string ."<br />\n";
}
does not work, and you have to do:
$string = "foo";
for($i = 0;$i <= strlen($string);$i++) {
echo $string{$i} ."<br />\n";
}
like I said, give this some thought, perhaps toss it around on php-dev
etc..
- Davey
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=20893&edit=1