Forum Moderators: coopster
$foo = "hello";
$secondchar = $foo{1};
echo $secondchar;
outputs "e"
I guess you could always loop through it and build your "real" array as you go or simply use this format.
more info on strings [php.net]
[added]From the manual, you can use normal array braces ("[" and "]") for strings but it's deprecated in favor of "{" and "}" as of php 4.[/added]
mavherick
$array = array();
$string = "The string to turn into an array";
$len = strlen($string);
for($i = 0;$i < $len;$i++)
{
array_push($array,$string[$i]);
}
print_r($array);
'course it all depends what you want to push into an array, if its a matter of finding words in a sentence, the strtok() function does the job well.