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!! Link to comment https://forums.phpfreaks.com/topic/136113-split-word-into-individual-letters/ 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]; Link to comment https://forums.phpfreaks.com/topic/136113-split-word-into-individual-letters/#findComment-709754 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 Link to comment https://forums.phpfreaks.com/topic/136113-split-word-into-individual-letters/#findComment-709758 Share on other sites More sharing options...
Mark Baker Posted December 9, 2008 Share Posted December 9, 2008 $word = "WORD"; $letters = str_split($word); Link to comment https://forums.phpfreaks.com/topic/136113-split-word-into-individual-letters/#findComment-710369 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. Link to comment https://forums.phpfreaks.com/topic/136113-split-word-into-individual-letters/#findComment-710371 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.