benanamen Posted October 28, 2015 Share Posted October 28, 2015 Did you know that Php variables are Arrays? Bet you didn't. $var="Hello"; echo $var[1];// =e echo $var[4];// =0 Quote Link to comment https://forums.phpfreaks.com/topic/298876-did-you-know/ Share on other sites More sharing options...
Jacques1 Posted October 28, 2015 Share Posted October 28, 2015 This has nothing to do with variables. It's simply that you can use the index notation to access characters in a string (which is a well-known feature). Quote Link to comment https://forums.phpfreaks.com/topic/298876-did-you-know/#findComment-1524531 Share on other sites More sharing options...
gizmola Posted October 28, 2015 Share Posted October 28, 2015 To elaborate on Jacques comment, PHP is a loosely typed language the does all sorts of type casting on the fly. You can try this for example, and you'll get a very different result than the one you got in your example, where php was working with a string type internally. <?php $v = 77; echo $v . "\n"; echo $v[0] . "\n"; echo $v[1] . "\n"; echo "Done\n"; Quote Link to comment https://forums.phpfreaks.com/topic/298876-did-you-know/#findComment-1524537 Share on other sites More sharing options...
benanamen Posted October 28, 2015 Author Share Posted October 28, 2015 Ok, I should have said "strings" can be accessed "like" an array. Of course you know @Jacques1. It was meant for noobs. Glad I can count on you guys to keep a brutha on his toes. Quote Link to comment https://forums.phpfreaks.com/topic/298876-did-you-know/#findComment-1524540 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.