for-lado-casino - 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 for-lado-casino.php

  1. <?php
  2. $source = [
  3.     [
  4.         "casino"  => "10 BET",
  5.         "dro"     => "22:15",
  6.         "matchi"  => "Zurich - Basel",
  7.         "result1" => "1.50",
  8.         "result2" => "1.50",
  9.         "result3" => "2.50"
  10.     ],
  11.     [
  12.         "casino"  => "10 BET",
  13.         "dro"     => "22:15",
  14.         "matchi"  => "Barcelona - real",
  15.         "result1" => "3.50",
  16.         "result2" => "1.50",
  17.         "result3" => "2.50"
  18.     ],
  19.     [
  20.         "casino"  => "20 BET",
  21.         "dro"     => "22:15",
  22.         "matchi"  => "Zurich - Basel",
  23.         "result1" => "4.50",
  24.         "result2" => "1.50",
  25.         "result3" => "2.50"
  26.     ],
  27. ];
  28.  
  29. function array_group_by($array, $key, $mapCb)
  30. {
  31.     $group = [];
  32.     foreach ($array as $value) {
  33.         if (empty($group[$value[$key]])) {
  34.             $group[$value[$key]] = [];
  35.         }
  36.         array_push($group[$value[$key]], $mapCb($value));
  37.     }
  38.  
  39.     return $group;
  40. }
  41.  
  42. function array_print($array)
  43. {
  44.     print( "<pre>" . print_r($array, true) . "</pre>" );
  45. }
  46.  
  47. function get_grouped($source)
  48. {
  49.     return array_group_by($source, "matchi", function ($value) {
  50.         return [
  51.             "casino"  => $value['casino'],
  52.             "result1" => (float) $value['result1'],
  53.             "result2" => (float) $value['result2'],
  54.             "result3" => (float) $value['result3']
  55.         ];
  56.     });
  57. }
  58.  
  59. function get_casino_max_results($arr, $casinoName)
  60. {
  61.     $r1 = [
  62.         'casino'=>$casinoName,
  63.         'result'=>0
  64.     ];
  65.     $r2 = [
  66.         'casino'=>$casinoName,
  67.         'result'=>0
  68.     ];
  69.     $r3 = [
  70.         'casino'=>$casinoName,
  71.         'result'=>0
  72.     ];
  73.     foreach ($arr as $key => $value) {
  74.         if ($r1['result'] < $value['result1']) {
  75.             $r1['result']  = $value['result1'];
  76.         }
  77.         if ($r2['result']  < $value['result2']) {
  78.             $r2['result']  = $value['result2'];
  79.         }
  80.         if ($r3['result']  < $value['result3']) {
  81.             $r3['result']  = $value['result3'];
  82.         }
  83.     }
  84.  
  85.     return [
  86.         $r1,
  87.         $r2,
  88.         $r3,
  89.     ];
  90. }
  91.  
  92. function get_mapped($array)
  93. {
  94.     $result = [];
  95.     foreach ($array as $key => $value) {
  96.         $result[] = [
  97.             'matchi'      => $key,
  98.             'max_results' => get_casino_max_results($value, $key),
  99.             'casinos'     => $value,
  100.         ];
  101.     }
  102.  
  103.     return $result;
  104. }
  105.  
  106. $result = get_mapped(get_grouped($source));
  107.  
  108. var_dump($result);
  109.  
File Description
  • for-lado-casino
  • PHP Code
  • 25 Apr-2019
  • 2.32 Kb
You can Share it: