As the view is passed the numeric value of the variable between the values of the array?

The essence of the problem is this:
On the website there is a slider that adjusts the price range and transmits a value of 2, such as "price=1000 and price=2000"

in turn, these values are elements of, for example, this array:

$filters = [
 'Categories (xyz..)' => 'Shoes,Wedding shoes 1 pair',
 'Color' => ['white', 'beige'],
 'Size' => '35',
 'Manufacturer' => 'leatherette',
 'Wholesale price' => [1000, 2000],
];


Have a two-dimensional array of such content, which will search for the specified price range:

array (size=22)
 'A072C02' => 
 array (size=2)
 1 => 
 array (size=67)
 'ID' => string 'A072C02' (length=7)
 'Wholesale price' => 1404 float
 'Color' => string 'white' (length=10)
 'Size' => float 35
 "=> null
 2 => 
 array (size=67)
 'ID' => string 'A072C02' (length=7)
 'Wholesale price' => 2100 float
 'Color' => string 'white' (length=10)
 'Size' => float 36 " => null


The problem: if the price (Wholesale price) is not suitable, then remove the inner element of the array (the 2nd, for example). Task simplified as I could. I would be grateful for the correct line of thought.
June 8th 19 at 17:23
2 answers
June 8th 19 at 17:25
$range = [1000, 2000];
foreach($items as $key => $item) {
 $price = $item['price'];
 if ($price < $range[0] || $price > $range[1]) {
unset($items[$key]);
}
}
But if this array is chosen from the database, then perhaps it is better to specify in the query.
June 8th 19 at 17:27
This is a trivial task and it is not done at the level of php is done on the database level. Ie is the task of the base to give the required sample, to form an array. Otherwise, why then do we need would be SQL?
Do not work with SQL. There is an Excel spreadsheet - from her to drag the data through PHPExcel in the array. If the PLO to implement - convenient to the array of filters in the method of a class responsible for sorting and in accordance with the received filter to adjust the original array.

The decision is written. If compactly, without inheritance and polymorphism, use this:
$data - array of data from excel (two-dimensional)
$filters - array of filters

public function filteringData($data, $filters) {
 $filterData = $data;
 foreach ($filterData as $string => $string) {
 foreach ($filters as $filter => $value) {
 if (!is_array($value)) { //if not an array, ie single value
 if ($string[$filter] != $value) {
unset($filterData[$strings]);
}
 } elseif (is_integer($value[0]) and is_integer($value[1]) and count($value) == 2) {//if the array price range
 if (!($string[$filter] > $value[0] and $string[$filter] < $value[1])) {
unset($filterData[$strings]);
}
 } else {//if the array is not with the price range
 if (!in_array($string[$filter], $value)) {
unset($filterData[$strings]);
}
}
}
}
 return $filterData;
 }


Thanks for the tip - phoebe_McGly commented on June 8th 19 at 17:30

Find more questions by tags PHPArrays