Vivid Lust Posted December 8, 2008 Share Posted December 8, 2008 Say I had this: $foo = "WORD"; how could I do this: $BAR[1] = "W"; $BAR[2] = "O"; ... Thanks!! Quote Link to comment Share on other sites More sharing options...
flyhoney Posted December 8, 2008 Share Posted December 8, 2008 It already works that way I think. $string = 'foo'; echo $string[1]; Quote Link to comment Share on other sites More sharing options...
Brian W Posted December 8, 2008 Share Posted December 8, 2008 Say I had this: $foo = "WORD"; how could I do this: $BAR[1] = "W"; $BAR[2] = "O"; ... Thanks!! if not what flyhoney said, then try $foo = "WORD"; $letter = explode("", $foo); echo $letters[0]; //output should be W Quote Link to comment Share on other sites More sharing options...
Mark Baker Posted December 9, 2008 Share Posted December 9, 2008 $word = "WORD"; $letters = str_split($word); Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted December 9, 2008 Share Posted December 9, 2008 Like flyhoney said, you can already address strings by their individual characters. <?php $str = "test" echo $str[0]; // t ?> just use a for() loop to iterate through it instead of a foreach() loop. Quote Link to comment 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.