Jump to content

How do I return a character of a string at index $i?


bobleny

Recommended Posts

Hi, I have a quick little baby question. I'm simply having difficulties searching for the answer.

 

I want to look at each character of a string.

 

This will work:

$var = "Joe";
echo strlen($var) ."<br />";
for($i = 0; $i < strlen($var); $i++)
{
echo $i. $var[$i] ."<br />";
}

 

It will print:

3
0J
1o
2e

----------

 

That is, believe it or not, exactly what I want to do. However, I don't think that is the proper way of doing it. Is there not a pre-built function designed to return a character of a string at index $i?

 

It has been my experience, that the way I am doing it above will either malfunction or will simply not work / won't compile.

 

 

Thanks for you help!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.