visitor (0 QPoints)
  • FR
  • EN
  • NL
  • DE
  • ES
315 experts, 1193 registered users, 1659 questions already answered
European Experts Exchange, the very best site for high-quality IT solutions

New Improved Search!

 


05/10/2011 1h30 : Steve Jobs is dead, the father of Apple ][ is gone, we are all orphaned.

Languages :: PHP :: Knowledge Base : How to get all phone number combinations of letters ?


By: VGR France  Date: 18/03/2005 11:51:33  English  Points: 0 Status: Answered
Quality : Good
Dated 07/05/2003

<?php // ----- Functions function Recursion($par,$prev,&$resu,&$nb) { // algorithm : // if length>0 treat first char in a loop, call for the rest // else memorize result and get out recursively if (strlen($par)>0) { switch ($par[0]) { case 0 : $chars=array('0'); break; case 1 : $chars=array('1'); break; case 2 : $chars=array('A','B','C'); break; case 3 : $chars=array('D','E','F'); break; case 4 : $chars=array('G','H','I'); break; // 'I' should be out (confusion with 1) case 5 : $chars=array('J','K','L'); break; case 6 : $chars=array('M','N','O'); break; // 'O' should be out (confusion with 0) case 7 : $chars=array('P','Q','R','S'); break; case 8 : $chars=array('T','U','V'); break; case 9 : $chars=array('W','X','Y','Z'); break; } // switch/case of foreach($chars as $char) { $newst=$prev.$char; Recursion(substr($par,1),$newst,$resu,$nb); } } else { // result found $resu[$nb]=$prev; // substr($resu[$nb-1],0,strlen($resu[$nb-1])-1); $nb++; } } // Recursion Procedure function DoIt($tel) { $resu=array(); $nb=0; Recursion($tel,"",$resu,$nb); return $resu; } // DoIt Array Function // ----- MAIN $numtel='4143'; $result=DoIt($numtel); // $result initialized in DoIt() $nbres=count($result); echo "number $numtel "; echo "$nbres combinations : "; for ($i=0;$i<$nbres;$i++) echo $result[$i].' '; ?>

By: VGR Date: 18/03/2005 11:52:09 English  Type : Comment
The results :

number 4143 27 combinations : G1GD G1GE G1GF G1HD G1HE G1HF G1ID G1IE G1IF H1GD H1GE H1GF H1HD H1HE H1HF H1ID H1IE H1IF I1GD I1GE I1GF I1HD I1HE I1HF I1ID I1IE I1IF


Do register to be able to answer

EContact
browser fav
page generated in 348.066810 milliseconds

Why Google AdSense ads ?

compteur
 Ranking-Hits PageRank for this page