Turn a word into an array in PHP
Was mucking around with creating a little word game the other day and needed to turn a string in to an array, this is how it was done:
$word = 'words';
$len = strlen($word);
$exploded_word = array();
for($i = 0; $i < $len; $i++) {
$exploded_word[] = $word[$i];
}
Would produce:
$word = 'words';
$len = strlen($word);
$exploded_word = array();
for($i = 0; $i < $len; $i++) {
$exploded_word[] = $word[$i];
}
Array
(
[0] => w
[1] => o
[2] => r
[3] => d
[4] => s
)


0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home