PHP: Split a string in to an array foreach char
You can access characters in strings in the same way as you would access an array index, e.g.
$length = strlen($string);$thisWordCodeVerdeeld = array();for ($i=0; $i<$length; $i++) { $thisWordCodeVerdeeld[$i] = $string[$i];}
You could also do:
$thisWordCodeVerdeeld = str_split($string);
However you might find it is easier to validate the string as a whole string, e.g. using regular expressions.
You can access a string using []
, as you do for arrays:
$stringLength = strlen($str);for ($i = 0; $i < $stringLength; $i++) $char = $str[$i];