On Thu, 11 Jul 2002 13:50:59 +0200, you wrote:

>> >Is there an easy way to get an array of characters from a string?
>> $str = 'string';
>> $chars = preg_split('//', $str, -1, PREG_SPLIT_NO_EMPTY);
>> print_r($chars);
>
>A string is already an array of chars :
>$toto="test";
>echo $toto[0]; // prints t
>echo $toto[1]; // prints e
>echo $toto[2]; // prints s
>echo $toto[3]; // prints t

Not really; a string is better described as a type that has some
properties in common with the array type. Consider these two examples:

<?
    $str = "Hello World!";
    $str = array_reverse($str);
    echo ($str);
?>

<?
    $str = "Hello World!";
    $chars = preg_split('//', $str, -1, PREG_SPLIT_NO_EMPTY);
    $str = implode('', array_reverse($chars));
    echo ($str);
?>

djo


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to