How can I split a string int an array for letters? For example:
$cat = "food";
and make $catarray = array("f","o","o","d")
http://www.php.net/manual/en/function.str-split.php
Anything for php 4?
Same page. User comments.
function str_split($str,$num = '1') { if($num < 1) return FALSE; $arr = array(); for ($j = 0; $j < strlen($str); $j= $j+$num) { $arr[] = substr($str,$j,$num); } return $arr; }
In your case, you dont need the split_length functionality, so you can use:
function strSplit($str) { $ret = array(); $len = strlen($str); for ($i = 0; $i < $len; $i++) { $ret[$i] = $str{$i}; } return $ret; }