fork download
  1. <?php
  2.  
  3.  
  4. function sendEmail($to, $msg) {
  5. echo "$msg $to\n";
  6. }
  7.  
  8.  
  9.  
  10. $skus = [
  11. '1234',
  12. '2341',
  13. '43253',
  14. '82344',
  15. '0001',
  16. ];
  17.  
  18. $dept = [
  19. 2 => '2@email.com',
  20. 3 => '3@email.com',
  21. 4 => '4@email.com',
  22. ];
  23.  
  24.  
  25. foreach($skus as $sku) {
  26. $digit = substr($sku, 0,1);
  27. if(array_key_exists($digit, $dept)) {
  28. sendEmail($dept[$digit], 'Send fulfillment order to ');
  29. }
  30. else {
  31. sendEmail('general@email.com', 'No specific department handles this. Send it to the general email.');
  32. } }
Success #stdin #stdout 0.02s 24412KB
stdin
Standard input is empty
stdout
No specific department handles this. Send it to the general email. general@email.com
Send fulfillment order to  2@email.com
Send fulfillment order to  4@email.com
No specific department handles this. Send it to the general email. general@email.com
No specific department handles this. Send it to the general email. general@email.com