I have the following array :
$output = array(
1507073550 => array(
0 => array(
"userid" => "1507073550"
"username" => "ma_alikhani"
"type" => "comment"
"profile_image" => "https://instagram.fgbb2-1.fna.fbcdn.net/v/t51.2885-19/s150x150/75538099_557824008392923_8054831368279949312_n.jpg?_nc_ht=instagram.fgbb2-1.fna.fbcdn.net&_nc_ohc"
)
1 => array(
"userid" => "11863258101"
"username" => "rasouli680"
"type" => "comment"
"profile_image" => "https://instagram.fgbb2-1.fna.fbcdn.net/v/t51.2885-19/s150x150/70326284_949495768737898_5241573836020776960_n.jpg?_nc_ht=instagram.fgbb2-1.fna.fbcdn.net&_nc_ohc"
)
2 => array(
"userid" => "16528062"
"username" => "alireza"
"type" => "comment"
"profile_image" => "https://instagram.fgbb2-1.fna.fbcdn.net/v/t51.2885-19/s150x150/70597112_740563976416368_5253996423334068224_n.jpg?_nc_ht=instagram.fgbb2-1.fna.fbcdn.net&_nc_ohc"
)
)
16528062 => array(
0 => array(
"userid" => "16528062"
"username" => "alireza"
"type" => "comment"
"profile_image" => "https://instagram.fgbb2-1.fna.fbcdn.net/v/t51.2885-19/s150x150/70597112_740563976416368_5253996423334068224_n.jpg?_nc_ht=instagram.fgbb2-1.fna.fbcdn.net&_nc_ohc"
)
1 => array(
"userid" => "1507073550"
"username" => "ma_alikhani"
"type" => "comment"
"profile_image" => "https://instagram.fgbb2-1.fna.fbcdn.net/v/t51.2885-19/s150x150/75538099_557824008392923_8054831368279949312_n.jpg?_nc_ht=instagram.fgbb2-1.fna.fbcdn.net&_nc_ohc"
)
)
)
and I want to intersection of keys of this array. get first key "1507073550" and second key "16528062" and intersect all of their data. it's not always have 2 keys, it might have +2 keys, i wrote this code but I'm getting array to string conversion error.
$keys = array_keys($output);
foreach ($keys as $index => $values)
{
$current_value = $output[$values]; // or $current_value = $a[$keys[$index]];
$next_key = next($keys);
$next_value = $output[$next_key] ?? null; // for php version >= 7.0
$a[] = array_intersect_assoc($current_value,$next_value);
}
and I'm expecting this result :
array(
0 => array(
"userid" => "1507073550"
"username" => "ma_alikhani"
"type" => "comment"
"profile_image" => "https://instagram.fgbb2-1.fna.fbcdn.net/v/t51.2885-19/s150x150/75538099_557824008392923_8054831368279949312_n.jpg?_nc_ht=instagram.fgbb2-1.fna.fbcdn.net&_nc_ohc"
)
1 => array(
"userid" => "16528062"
"username" => "alireza"
"type" => "comment"
"profile_image" => "https://instagram.fgbb2-1.fna.fbcdn.net/v/t51.2885-19/s150x150/70597112_740563976416368_5253996423334068224_n.jpg?_nc_ht=instagram.fgbb2-1.fna.fbcdn.net&_nc_ohc"
)
)
I really don't know how to do it ! I'd be appreciated for your helps.
To use: