Can someone pls explain me why does the following code prints "t"?
$a = "print";
Because you can treat a string sort of like an array of characters, and since it's a zeroth based array, index 4 is the 5th character.
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
How to Ask Questions the Smart Way
(not affiliated with this site, but well worth reading)
This is because you are using array. array means it starts from '0' and then continue till '4' which total is '5' numbers. So the in word "print" it will count form '0' and will print the 5th character as in the array you have mentioned .
Hope your problem is solved.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)