3v4l.org

run code in 300+ PHP versions simultaneously
<?php $ticketTypes = [ "ticketTypes" => [ "557968" => [ "section" => "235606", "amount" => "1" ], "604142"=> [ "section"=> "253594", "amount"=> "2" ] ], "delivery"=> [ "digitalPrintPass", "willcall", "mail", "digitalPrintPass" ] ]; $resultTypes = []; $deliveryOptions = []; $deliveryValues = ""; foreach ($ticketTypes as $key => $value) { if($key == 'ticketTypes'){ // print_r($key); -- printing "tickettypes" // print_r($value); $i = 0; foreach($value as $ticketTypeId => $sectionInfo){ $resultTypes[$i] = [ "ticketTypeId" => $ticketTypeId, "sectionId" => $sectionInfo['section'], "sectionAmount" => $sectionInfo['amount'] ]; $i++; } print_r($resultTypes); }elseif($key == 'delivery'){ foreach($value as $deliveryOption){ switch ($deliveryOption) { case "digitalPrintPass": $deliveryOptions[] = 'H'; break; case "willcall": $deliveryOptions[] = 'W'; break; case "mail": $deliveryOptions[] = 'M'; break; } } $deliveryValues = implode(",", $deliveryOptions); // $resultTypes[0] = [] } echo $deliveryValues; } // DONE -----> expect an array of price types (TICKET_TYPE) matched with a section and a quantity // DONE -----> create an empty array called something like matchingRequests // loop through all requests still in "REQUESTED" (see WAITLIST_STATUS table) state (possibly limited only to requests with selected price types), ordered by earliest submission time first. waitlist status table requested is id 1 // SQL_BSWAITLISTREPORTGET is a good starting point to find these requests, but we might want to make this a function in the waitlist class // if a request cannot be fulfilled in full (ticket type wasn't selected or quantity is no longer available) skip it // if the request can be fulfilled, include it in the matchingRequests array and decrement requested quantity for the section // return the matchingRequests as a json object // $a = json_encode($b); // echo $a; // $a = { // "ticketTypes": { // "557968": { // "section": "235606", // "amount": "1" // }, // "604142": { // "section": "253594", // "amount": "2" // } // }, // "delivery": { // "digitalPrintPass", // "willcall" // } // };
Output for 7.4.0 - 7.4.33, 8.0.1 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Array ( [0] => Array ( [ticketTypeId] => 557968 [sectionId] => 235606 [sectionAmount] => 1 ) [1] => Array ( [ticketTypeId] => 604142 [sectionId] => 253594 [sectionAmount] => 2 ) ) H,W,M,H

preferences:
114.31 ms | 402 KiB | 120 Q