Linjon Posted July 17, 2011 Share Posted July 17, 2011 Hello. How to make two variables to alphabet? Example: $variable1 = ace $variable2 = bd and script makes abcde Hope you understand, sorry for my bad English Quote Link to comment https://forums.phpfreaks.com/topic/242218-php-alphabet/ Share on other sites More sharing options...
Alex Posted July 17, 2011 Share Posted July 17, 2011 $arr = str_split($variable1 . $variable2); sort($arr); echo implode($arr); str_split sort implode Quote Link to comment https://forums.phpfreaks.com/topic/242218-php-alphabet/#findComment-1243878 Share on other sites More sharing options...
Linjon Posted July 17, 2011 Author Share Posted July 17, 2011 Thanks Alex. I have question again. If there is "a" in $variable1 and also there is "a" in $variable2 then it will echo "aa". How to make it show "a" once ? Quote Link to comment https://forums.phpfreaks.com/topic/242218-php-alphabet/#findComment-1243890 Share on other sites More sharing options...
Alex Posted July 17, 2011 Share Posted July 17, 2011 Use array_unique to get rid of duplicates: $arr = str_split($variable1 . $variable2); sort($arr); echo implode(array_unique($arr)); Quote Link to comment https://forums.phpfreaks.com/topic/242218-php-alphabet/#findComment-1243894 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.