americano code snipets - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of americano code snipets.php

  1. <?php
  2.  $players = ['Paquito', 'Bela', 'Gutierrez', 'Lebron', 'Silingo', 'Galan', 'Chingotto', 'Tapia', '9', '10', '11', '12'];
  3.         $combo  = [];
  4.         $totalPlayers = sizeof($players);
  5.  
  6.         foreach ($players as $k => $p) {
  7.  
  8.             foreach ($players as $fp) {
  9.                 if ($p == $fp) {
  10.                     continue;
  11.                 }
  12.  
  13.                 $string = "$p&$fp";
  14.                 $data = [
  15.                     'player1' => $p,
  16.                     'player2' => $fp,
  17.                 ];
  18.                 array_push($combo, $data);
  19.  
  20.             }
  21.             array_splice($players, 0, 1);
  22.  
  23.         }
  24.         //return $combo;
  25.         $matchs = [];
  26.         $roundedMatches = [];
  27.         foreach ($combo as $k => $player) {
  28.  
  29.             foreach ($combo as $m => $player2) {
  30.                 if (!in_array($player2['player1'], $matchs) && !in_array($player2['player2'], $matchs)) {
  31.                     array_push($matchs, $player2['player1']);
  32.                     array_push($matchs, $player2['player2']);
  33.                     unset($combo[$m]);
  34.  
  35.                 }
  36.  
  37.                 if (count($matchs) == $totalPlayers) {
  38.                     array_push($roundedMatches, $matchs);
  39.                     $matchs = [];
  40.                 }
  41.  
  42.             }
  43.         }
  44.  
  45.         print_r($roundedMatches);
File Description
  • americano code snipets
  • PHP Code
  • 31 Dec-2020
  • 1.28 Kb
You can Share it: