Answer the question
In order to leave comments, you need to log in
How to implement filtering an array of objects with multiple parameters, which can have multiple values?
There is an array of objects, an object has several parameters, and each parameter can have several values. You need to do a search in this array with the given parameter values. For example
, the array consists of objects of the type Car
Parameters of the car
weight - 2000kg
color - red,
speed blue - 1,2,3, back
request example all - [unspecified], color - red, speed - 2
Answer the question
In order to leave comments, you need to log in
I can offer you 2 solutions.
The first banal foreach with comparison.
The second one will require PC memory, but can greatly speed up the filtering process.
At the moment of collecting objects into an array, you need to create another one in which the property will be the key, and the object references will be the values.
$arrayProp = array(
'red' => array( &link_to_object ),
'2' => array( &link_to_object )
);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question