Answer the question
In order to leave comments, you need to log in
How to group a multidimensional array by overlapping values of another PHP array?
Tell me how to split the First array into arrays according to the match condition in the string of the value post_title
from the Second array ?
First array
[0] => Array
(
[ID] => 80433
[post_title] => Консоль из нержавеющей 1
)
[1] => Array
(
[ID] => 80428
[post_title] => Комод из неражавеющей 2
)
[0] => Консоль
[1] => Комод
Answer the question
In order to leave comments, you need to log in
Nonsense, sure, but still:
<?php
$items = [
['ID' => 80433, 'post_title' => 'Консоль из нержавеющей 1'],
['ID' => 80428, 'post_title' => 'Комод из неражавеющей 2']
];
$categories = ['Консоль', 'Комод'];
$result = [];
foreach($categories as $category) {
$results[$category] = [];
foreach($items as $item) {
if (mb_strpos(mb_strtolower($item['post_title']), mb_strtolower($category)) !== false) {
$result[$category][] = $item;
}
}
}
print_r($result);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question