Answer the question
In order to leave comments, you need to log in
Is there a PHP library for filtering an sql array with a query?
It often happens that there is an array of data
$arr=[
["name"="Kolya", "age"="13", "sex"="m"],
["name"="Vasya", "age" ="20, "sex"="m"],
["name"="Olya", "age"="10", "sex"="f"],
];
And you need to remove all the boys from it from the beginning up to 15, then all Ol from 5, etc. Is there any
PHP
library for this?
,20)->filter("sex","m")
is very hard to read and difficult to understand.
Answer the question
In order to leave comments, you need to log in
You can use https://github.com/illuminate/support
It has a Collection that can do a lot of useful things with arrays/objects.
There are also filter, find, contains and other functions.
You can create a table, fill in the data there, and select using SQL. Performance is likely to be so-so, but the heroes are not looking for easy ways. And do not care about the curses from those who fit into this code later.
In raw php, it might look something like this:
$result = array_filter($data, function($d){
return $d['sex'] == 'm' && $d['age'] <= 15;
});
$boys = array_filter($data, 'filterBoys');
// а где-то там, в другом месте
function filterBoys($d){
return $d['sex'] == 'm' && $d['age'] <= 15;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question