faqts : Computers : Programming : Languages : PHP : Common Problems : Strings

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

13 of 26 people (50%) answered Yes
Recently 4 of 10 people (40%) answered Yes

Entry

How can I turn a string into an array?

Aug 7th, 1999 23:03
Nathan Wallace, unknown unknown, James Reed


A string ($foo) is already an array. You can do something like this to
walk across the string like an array:

The only difference is that instead of using count() to find the number
of elements in this "array", you use strlen().

    <?
    $foo = "abcdefghi";

    for ($i=0; $i<strlen($foo); $i++) {
        echo $i, " -- ", $foo[$i], "<br>";
    }
    ?>