Page 1 of 1

Splitting letters in string into mult. array

Posted: Tue Oct 28, 2003 6:57 pm
by nigma
Say I have the following text

abcdefg
hijklmn


And I want to put it into a multidimensional array so that doing

Code: Select all

print $arrayName[1][2];
would print out "b" (b is 2nd char in 1st row).

Anyone be able to point me in the right direction?

Posted: Tue Oct 28, 2003 7:10 pm
by JAM

Code: Select all

<pre>
<?php
    $text[] = 'abcdefg';
    $text[] = 'hijklmn';
    
    function printit($row,$char) {
        global $text;
        return substr($text[$row-1],$char-1,1);
    }
    echo printit(2,2); // i
?>
Note that I'm bypassing that array and first letter actually is 0.

Posted: Tue Oct 28, 2003 8:21 pm
by nigma
Thanks a lot JAM. After reading your reply I went to php.net and checked out their man page for substr. Apreciate your help.

Posted: Tue Oct 28, 2003 8:24 pm
by JAM
Welcome. Thinking that there might be another function for this, but I can't... find... it...

If noone posts something else, pretend there isn't...