3v4l.org

run code in 300+ PHP versions simultaneously
<?php $alfabeth = str_split('ABCDEFGHIJKLMNOPQRSTUVWXYZ'); $comets_by_group = [ 'HALLEY' => 'AMARELO', 'ENCKE' => 'VERMELHO', 'WOLF' => 'PRETO', 'KUSHIDA' => 'AZUL' ]; $sum_position_by_words = function($word) use($alfabeth) { $result = 0; foreach(str_split($word) as $letter) { if(in_array($letter, $alfabeth)) { $value_by_letter = ++array_keys($alfabeth, $letter)[0]; $result *= $value_by_letter; } } return $result; }; $complement = (php_sapi_name() != 'cli') ? "<br>\n" : "\n"; foreach($comets_by_group as $comet => $group) { if($sum_position_by_words($comet) % 45 == $sum_position_by_words($group) % 45){ printf("The group %s of comet %s" . $complement, $comet, $group); } }

preferences:
50.16 ms | 402 KiB | 5 Q