Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $luggage = preg_split('/\s*C\|_\|\s*/', $_GET['luggage'], -1, PREG_SPLIT_NO_EMPTY);
- $typeLuggage = array();
- if (isset($_GET['typeLuggage'])) {
- foreach ($_GET['typeLuggage'] as $type) {
- $typeLuggage[] = $type;
- }
- }
- $room = $_GET['room'];
- $minWeight = $_GET['minWeight'];
- $maxWeight = $_GET['maxWeight'];
- if (empty($typeLuggage) || $room == '' || $minWeight == '' || $maxWeight == '') {
- die('<ul></ul>');
- }
- $minWeight = (int)$minWeight;
- $maxWeight = (int)$maxWeight;
- $filteredLuggage = array();
- $typeWeightArr = array();
- foreach ($luggage as $piece) {
- $pieceInfo = preg_split('/\s*\;\s*/', $piece, -1, PREG_SPLIT_NO_EMPTY);
- $type = $pieceInfo[0];
- if (!in_array($type, $typeLuggage) || $pieceInfo[1] != $room) {
- continue;
- }
- if (!array_key_exists($type, $filteredLuggage)) {
- $filteredLuggage[$type] = array();
- $typeWeightArr[$type] = 0;
- }
- $luggageName = $pieceInfo[2];
- $typeWeightArr[$type] += (int)$pieceInfo[3];
- array_push($filteredLuggage[$type], $luggageName);
- }
- foreach ($typeWeightArr as $type => $weight) {
- if ($weight < $minWeight || $weight > $maxWeight) {
- unset($typeWeightArr[$type]);
- unset($filteredLuggage[$type]);
- }
- }
- ksort($filteredLuggage);
- $result = '<ul>';
- foreach ($filteredLuggage as $type => $list) {
- sort($list);
- $result .= '<li><p>' . $type . '</p><ul><li><p>' . $room . '</p><ul><li><p>';
- $result .= implode(', ', $list) . ' - ' . $typeWeightArr[$type] . 'kg</p></li></ul></li></ul></li>';
- }
- echo $result . '</ul>';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement