PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
Copy Clear
Copy Format Clear
<?php global $items; $items = [ 0 => (object)[ 'title' => 'title1', 'price' => 123, 'size' => 'dsccacds' ], 1 => (object)[ 'title' => 'title2', 'price' => 11, 'size' => 'iuouiouio' ], 2 => (object)[ 'title' => 'title3', 'price' => 50, 'size' => 'xcvzxv' ], 3 => (object)[ 'title' => 'title3', 'price' => [ 0 => (object) [ 'price' => 40, 'size' => 'sqwer' ], 1 => (object) [ 'price' => 59, 'size' => 'wqerqewrqwrqwerqewr' ] ] ] ]; test(9, 60, $items); function test (int $minPrice, int $maxPrice, array $items) { $result = []; $result2 = []; foreach ($items as $item) { if(is_array($item->price)){ if($item->price[0]->price > $minPrice && $item->price[count($item->price)-1] < $maxPrice){ $result[$item->price[0]->price] = $item; }; } else { if($item->price > $minPrice && $item->price < $maxPrice){ $result[$item->price] = $item; } } } //echo "\n"; //echo "массивы из result"; //echo "\n"; ksort($result); echo var_dump($result); }
Show:  
Copy Clear