Tuesday, January 24, 2012

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:
Array
(
    [0] => w
    [1] => o
    [2] => r
    [3] => d
    [4] => s
)

Labels: ,

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home