fork download
  1. <?php
  2.  
  3. $number = "44777777";
  4.  
  5. // Add your loop here to check for 3, 2, 1 digit
  6. $we = substr($number, 0, 3);
  7.  
  8. $countrys = array(
  9. '1' => 'us',
  10. '2' => 'uk',
  11. '3' => 'de',
  12. '44' => 'fi',
  13. '123' => 'no'
  14. );
  15.  
  16. $array = "$we"; // You don't need this
  17.  
  18. if (array_key_exists ($we, $countrys))
  19. {
  20. // Remember to break out of your loop when the country is found
  21. $country = $countrys[$we];
  22. }
  23. else
  24. {
  25. $country = "Non in list";
  26. }
  27. // End your loop here
  28.  
  29. echo "${we} is ${country}\n";
Success #stdin #stdout 0.01s 20568KB
stdin
Standard input is empty
stdout
447 is Non in list