3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $e = array( "tracker1" => 'a1', 'tracker2' => 'a2', 'tracker3' => 'a3', 'tracker4' => 'a4', "tracker5" => 'a5', 'tracker6' => 'a6', 'tracker7' => 'a7', 'tracker8' => 'a8', 'tracker0' => 'a9', ); $carrier = "empty"; foreach($e as $key => $value){ if(strtolower(trim($value)) === strtolower(trim($carrier))){ //if match tracker[0-9], map. Else, keep going if(preg_match("/^tracker[0-9]/", $key)){ $carrier = $key; break; } } } echo $carrier."\n\n"; $carrier = "a3"; foreach($e as $key => $value){ if(strtolower(trim($value)) === strtolower(trim($carrier))){ //if match tracker[0-9], map. Else, keep going if(preg_match("/^tracker[0-9]/", $key)){ $carrier = $key; break; } } } echo $carrier."\n\n"; $carrier = "a8"; foreach($e as $key => $value){ if(strtolower(trim($value)) === strtolower(trim($carrier))){ //if match tracker[0-9], map. Else, keep going if(preg_match("/^tracker[0-9]/", $key)){ $carrier = $key; break; } } } echo $carrier."\n\n"; $carrier = "a9"; foreach($e as $key => $value){ if(strtolower(trim($value)) === strtolower(trim($carrier))){ //if match tracker[0-9], map. Else, keep going if(preg_match("/^tracker[0-9]/", $key)){ $carrier = $key; break; } } } echo $carrier."\n\n";
based on svSvh
Output for 5.6.0 - 7.3.0rc3
empty tracker3 tracker8 tracker0