3v4l.org

run code in 300+ PHP versions simultaneously
<?php function groupBySameLetters(array $words): array { $groups = []; foreach ($words as $word) { $letters = mb_str_split($word); sort($letters); $key = implode('', $letters); $groups[$key][] = $word; $groups[$key] ++; } return array_values($groups); } // Приклад використання: $input = ['ab', 'ac', 'ba', 'ca']; $result = groupBySameLetters($input); print_r($result);
Output for 8.1.34, 8.2.27 - 8.2.30, 8.3.0 - 8.3.29, 8.4.1 - 8.4.16, 8.5.0 - 8.5.1
Fatal error: Uncaught TypeError: Cannot increment array in /in/vapPb:13 Stack trace: #0 /in/vapPb(21): groupBySameLetters(Array) #1 {main} thrown in /in/vapPb on line 13
Process exited with code 255.

preferences:
33.09 ms | 406 KiB | 5 Q