PHP Explode Each Character Function
This function is like PHP's explode() funtion, but instead of having a delimiter, it separates each character into it's own array piece.
For example, explodeEachChar('cat') would return array(0 => 'c', 1 => 'a', 2 => 't').
<?php
function explodeEachChar($x) {
$c = array();
while (strlen($x > 0)) {
$c[] = substr($x,0,1);
$x = substr($x,1);
}
return $c;
}
?>
Note: You can also use PHP's split() function to achieve this. Whichever is easier for you.
Last updated on November 8, 2009.