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 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 print_max_results_table($array)
- {
- echo '<table border="1">';
- echo '<tr>';
- echo '<th>Type</th>';
- echo '<th>Casino</th>';
- echo '<th>Result</th>';
- echo '</tr>';
- foreach ($array as $key => $value) {
- echo '<tr>';
- echo "<td>";
- if($key === 0){
- echo '1';
- }
- if($key === 1){
- echo 'x';
- }
- if($key === 2){
- echo '2';
- }
- echo "</td>";
- echo "<td>{$value['casino']}</td>";
- echo "<td>{$value['result']}</td>";
- echo '</tr>';
- }
- echo '</table>';
- }
- function print_casinos_table($array)
- {
- echo '<table border="1">';
- echo '<tr>';
- echo '<th>Casino</th>';
- echo '<th>1</th>';
- echo '<th>x</th>';
- echo '<th>2</th>';
- echo '</tr>';
- foreach ($array as $value) {
- echo '<tr>';
- echo "<th>{$value['casino']}</th>";
- echo "<th>{$value['result1']}</th>";
- echo "<th>{$value['result2']}</th>";
- echo "<th>{$value['result3']}</th>";
- echo '</tr>';
- }
- echo '</table>';
- }
- function print_match_list($array)
- {
- echo '<ul style="list-style: none">';
- foreach ($array as $item) {
- echo '<li style="display: block">';
- echo "Match: <b>{$item['matchi']}</b>";
- echo "<br>";
- echo '<br>Max Results: ';
- print_max_results_table($item['max_results']);
- echo '<br>Casinos: ';
- print_casinos_table($item['casinos']);
- echo '<hr>';
- echo '</li>';
- }
- echo '</ul>';
- }
- 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)
- {
- $r1 = [
- 'casino' => '',
- 'result' => 0
- ];
- $r2 = [
- 'casino' => '',
- 'result' => 0
- ];
- $r3 = [
- 'casino' => '',
- 'result' => 0
- ];
- foreach ($arr as $key => $value) {
- if ($r1['result'] < $value['result1']) {
- $r1['result'] = $value['result1'];
- $r1['casino'] = $value['casino'];
- }
- if ($r2['result'] < $value['result2']) {
- $r2['result'] = $value['result2'];
- $r2['casino'] = $value['casino'];
- }
- if ($r3['result'] < $value['result3']) {
- $r3['result'] = $value['result3'];
- $r3['casino'] = $value['casino'];
- }
- }
- return [
- $r1,
- $r2,
- $r3,
- ];
- }
- function get_mapped($array)
- {
- $result = [];
- foreach ($array as $key => $value) {
- $result[] = [
- 'matchi' => $key,
- 'max_results' => get_casino_max_results($value),
- 'casinos' => $value,
- ];
- }
- return $result;
- }
- $result = get_mapped(get_grouped($source));
- function array_print($array)
- {
- print( "<pre>" . print_r($array, true) . "</pre>" );
- }
- print_match_list($result);
File Description
- lado-casino
- PHP Code
- 25 Apr-2019
- 4.15 Kb
You can Share it:
Latest PHP Pastes