Answer the question
In order to leave comments, you need to log in
How to select the same value from two multidimensional arrays in php?
There are two multidimensional arrays after JSON parsing and processing
["items"]=> array(2)
{
[0]=> object(stdClass)#2 (4)
{
["id"]=> int(29)
["from_id"]=> int(-145381893)
["date"]=> int(1525428495)
["text"]=> string(181) "текст1"
}
[1]=> object(stdClass)#4 (4)
{
["id"]=> int(28)
["from_id"]=> int(72325239)
["date"]=> int(1525428062)
["text"]=> string(276) "текст2"
["profiles"]=> array(3)
{
[0]=> object(stdClass)#28 (3)
{
["id"]=> int(33367167)
["first_name"]=> string(10) "Иван"
["last_name"]=> string(22) "Иванов"
}
[1]=> object(stdClass)#29 (3)
{
["id"]=> int(72325239)
["first_name"]=> string(8) "Петр"
["last_name"]=> string(16) "Петров"
}
[2]=> object(stdClass)#30 (3)
{
["id"]=> int(123060350)
["first_name"]=> string(10) "Сергей"
["last_name"]=> string(16) "Сергеев"
}
}
Answer the question
In order to leave comments, you need to log in
$profiles = array_combine(
array_map(function($profile) { return $profile->id; }, $data['profiles']),
$data['profiles']);
foreach ($data['items'] as $item) {
echo $profile[$item->from_id]->first_name, ' ',
$profile[$item->from_id]->last_name, ' - ',
$items->text, "\n";
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question