I have to deal with a refactoring, to reduce the number of lines of code in PHP, to filter an associative array. So I'm making a select from DB in MySQL, to get an associative array. So my "Object" has a category and a surname field.
while ($row = mysqli_fetch_array($result)) {
$array[] = $row['category'];
$array[] = $row['Surname'];
}
I want to obtain from this array, as many other sub-array, splitted by the category. I mean the category Array identification may be:
$categories = array("A","B","C","D");
So what I want, is to obtain one Array for each Category, which contains all the Surname, of that category. So suppose that the method works, something like that:
$arrayFiltered = method_filter($array_asso,"A");
At the end I want something like that:
foreach ($categories as &$value) {
$arrayFiltered = method_filter($array_asso,$value);
my_method_which_needs_the_filtered_array($arrayFiltered);
}
Thank you in advance for your help.