3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arrays = array("foo-1" => array(array("A", 3), array("B", 3)), "foo-2" => array(array("A", 1), array("B", 7)), "foo-3" => array(array("A", 1), array("B", 6))); $names = "("; $letters = "("; $numbers = ""; $coordinate = ""; foreach($arrays as $arrayName => $array) { if(array_search($arrayName, array_keys($arrays)) == 0) { $names .= $arrayName; }else{ $names .= ",".$arrayName; } foreach($array as $key => $nestedArray) { foreach($nestedArray as $letterOrNum => $value) { if($letterOrNum == 0) { // it's a letter if($key + 1 == 1) { $nextLetter = $array[$key + 1][0]; if (!strpos($letters, $value.','.$nextLetter) !== false) { if($key == 0 && array_search($arrayName, array_keys($arrays)) == 0) { $letters .= $value; }else{ $letters .= ",".$value; } } }else{ $previousLetter = $array[$key - 1][0]; if (!strpos($letters, $previousLetter.','.$value) !== false) { if($key == 0 && array_search($arrayName, array_keys($arrays)) == 0) { $letters .= $value; }else{ $letters .= ",".$value; } } } }else{ // its a number if($key == 0) { $coordinate .= "(".$value.","; }else{ $coordinate .= $value.")"; } $numbers .= $coordinate; $coordinate = ""; } } } } $names .= ")"; $letters .= ")"; echo $names; echo $letters; echo $numbers;
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 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
(foo-1,foo-2,foo-3)(A,B)(3,3)(1,7)(1,6)

preferences:
126.08 ms | 407 KiB | 5 Q