3v4l.org

run code in 300+ PHP versions simultaneously
<?php $a=array('FA',12.9); $b=array('FA',12.9); $c=array('FB',12.2); $d=array('FC',12.3); $e=array('FA',12.9); $h=array('FA',12.4); $f=array('FB',12.9); $items=array($a,$b,$c,$d,$e,$f,$h); // Count in two different but functionally identical ways $counts_a = []; $counts_b = []; foreach($items as $item) { // Suppress the warning for missing key @$counts_a[$item[0] . ' ' . $item[1]]++; // Actually look for the key and set to zero if not found $key = $item[0] . ' ' . $item[1]; if(!array_key_exists($key, $counts_b)){ $counts_b[$key] = 0; } $counts_b[$key]++; } foreach($counts_a as $key => $count) { echo $key . 'x' . $count, PHP_EOL; }
Output for 7.4.0 - 7.4.33, 8.0.1 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.27, 8.4.1 - 8.4.14
FA 12.9x3 FB 12.2x1 FC 12.3x1 FB 12.9x1 FA 12.4x1

preferences:
108.33 ms | 406 KiB | 5 Q