Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $list = trim($_GET['list']);
- $minPrice = (double) trim($_GET['minPrice']);
- $maxPrice = (double) trim($_GET['maxPrice']);
- $filter = trim($_GET['filter']);
- $order = trim($_GET['order']);
- $result = '';
- if ($order == 'ascending') {
- $sort = SORT_ASC;
- } else if ($order == 'descending') {
- $sort = SORT_DESC;
- }
- $prds = preg_split('/\n/', $list);
- if (sizeof($prds) > 1 && $minPrice < $maxPrice) {
- $productsListList = array();
- $products = array();
- foreach ($prds as $key => $p) {
- $product = explode(' | ', $p);
- $productsList[$key]['id'] = $key + 1;
- $productsList[$key]['name'] = $product[0];
- $productsList[$key]['type'] = $product[1];
- $productsList[$key]['components'] = explode(', ', $product[2]);
- $productsList[$key]['price'] = (double) $product[3];
- }
- foreach ($productsList as $p) {
- if ($p['price'] >= $minPrice && $p['price'] <= $maxPrice && ($filter == $p['type'] || $filter == 'all')) {
- $cnt = sizeof($products);
- $products[$cnt] = $p;
- }
- }
- $products = multisort($products, SORT_ASC, 'id');
- $products = multisort($products, $sort, 'price');
- foreach ($products as $p) {
- $result .= '<div class="product" id="product' . $p['id'] . '"><h2>' . htmlspecialchars($p['name']) . '</h2><ul>';
- foreach ($p['components'] as $c) {
- $result .= '<li class="component">' . htmlspecialchars($c) . '</li>';
- }
- $result .= '</ul><span class="price">' . number_format($p['price'], 2, '.', '') . '</span></div>';
- }
- echo $result;
- }
- function multisort($arr, $ord, $property) {
- foreach ($arr as $id => $val) {
- $key[$id] = $val[$property];
- }
- array_multisort($key, $ord, $arr);
- return $arr;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement