PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
nigma
DevNet Resident
Posts: 1094 Joined: Sat Jan 25, 2003 1:49 am
Post
by nigma » Tue Oct 28, 2003 6:57 pm
Say I have the following text
abcdefg
hijklmn
And I want to put it into a multidimensional array so that doing
would print out "b" (b is 2nd char in 1st row).
Anyone be able to point me in the right direction?
JAM
DevNet Resident
Posts: 2101 Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:
Post
by JAM » Tue Oct 28, 2003 7:10 pm
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.
nigma
DevNet Resident
Posts: 1094 Joined: Sat Jan 25, 2003 1:49 am
Post
by nigma » Tue Oct 28, 2003 8:21 pm
Thanks a lot JAM. After reading your reply I went to php.net and checked out their man page for substr. Apreciate your help.
JAM
DevNet Resident
Posts: 2101 Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:
Post
by JAM » Tue Oct 28, 2003 8:24 pm
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...