note 77145 deleted from control-structures.foreach by danbrown
| From: | danbrown@php.net | Date: | Tue, 28 Apr 2009 13:03:29 +0000 |
| Subject: | note 77145 deleted from control-structures.foreach by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-153905@lists.php.net to get a copy of this message | ||
Note Submitter: john factorial
----
In response to gherson's method of foreach'ing over a string's characters, PHP 5 now
provides you with the str_split() function.
So, to foreach through the characters of a string in PHP 5:
<?php
$string="string";
$array = str_split($string);
foreach($array as $char) print($char."<br/>");
?>
This outputs:
s
t
r
i
n
g