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.
Result of php executing
Full code of for-lado-casino.php
- <?php
- $source = [
- [
- "casino" => "10 BET",
- "dro" => "22:15",
- "matchi" => "Zurich - Basel",
- "result1" => "1.50",
- "result2" => "1.50",
- "result3" => "2.50"
- ],
- [
- "casino" => "10 BET",
- "dro" => "22:15",
- "matchi" => "Barcelona - real",
- "result1" => "3.50",
- "result2" => "1.50",
- "result3" => "2.50"
- ],
- [
- "casino" => "20 BET",
- "dro" => "22:15",
- "matchi" => "Zurich - Basel",
- "result1" => "4.50",
- "result2" => "1.50",
- "result3" => "2.50"
- ],
- ];
- function array_group_by($array, $key, $mapCb)
- {
- $group = [];
- foreach ($array as $value) {
- if (empty($group[$value[$key]])) {
- $group[$value[$key]] = [];
- }
- array_push($group[$value[$key]], $mapCb($value));
- }
- return $group;
- }
- function array_print($array)
- {
- print( "<pre>" . print_r($array, true) . "</pre>" );
- }
- function get_grouped($source)
- {
- return array_group_by($source, "matchi", function ($value) {
- return [
- "casino" => $value['casino'],
- "result1" => (float) $value['result1'],
- "result2" => (float) $value['result2'],
- "result3" => (float) $value['result3']
- ];
- });
- }
- function get_casino_max_results($arr, $casinoName)
- {
- $r1 = [
- 'casino'=>$casinoName,
- 'result'=>0
- ];
- $r2 = [
- 'casino'=>$casinoName,
- 'result'=>0
- ];
- $r3 = [
- 'casino'=>$casinoName,
- 'result'=>0
- ];
- foreach ($arr as $key => $value) {
- if ($r1['result'] < $value['result1']) {
- $r1['result'] = $value['result1'];
- }
- if ($r2['result'] < $value['result2']) {
- $r2['result'] = $value['result2'];
- }
- if ($r3['result'] < $value['result3']) {
- $r3['result'] = $value['result3'];
- }
- }
- return [
- $r1,
- $r2,
- $r3,
- ];
- }
- function get_mapped($array)
- {
- $result = [];
- foreach ($array as $key => $value) {
- $result[] = [
- 'matchi' => $key,
- 'max_results' => get_casino_max_results($value, $key),
- 'casinos' => $value,
- ];
- }
- return $result;
- }
- $result = get_mapped(get_grouped($source));
- var_dump($result);
File Description
- for-lado-casino
- PHP Code
- 25 Apr-2019
- 2.32 Kb
You can Share it:
Latest PHP Pastes