アレイ1つの出力一致する場合、他の配列値を取得する方法は?
Array (
[0] => Array ([ID] => 335 [userid] => 4 [username] => demo [media_id] => 17)
[1] => Array ([ID] => 436 [userid] => 4 [username] => demo [media_id] => 18)
[2] => Array ([ID] => 637 [userid] => 4 [username] => demo [media_id] => 19)
[3] => Array ([ID] => 838 [userid] => 4 [username] => demo [media_id] => 20)
);
アレイ2の出力と一致する場合、他の配列値を取得する方法
Array (
[1] => Array ([ID] => 35 [userid] => 4 [media_id] => 17)
[2] => Array ([ID] => 36 [userid] => 4 [media_id] => 18)
);
?私はmedia_id
とuserid
のarray 2
がarray 1
に一致すれば、ID
とusername
をarray 1
からforeachループarray 2
に一致させる必要がありますか?
更新
$array1 = array (
0 => array ("ID" => "335", "userid" => "4", "username" => "demo", "media_id" => "17"),
1 => array ("ID" => "436", "userid" => "4", "username" => "demo", "media_id" => "18"),
2 => array ("ID" => "637", "userid" => "4", "username" => "demo", "media_id" => "19"),
3 => array ("ID" => "838", "userid" => "4", "username" => "demo", "media_id" => "20")
);
$array2 = array (
1 => array ("ID" => "35", "userid" => "4", "media_id" => "17"),
2 => array ("ID" => "36", "userid" => "4", "media_id" => "18")
);
foreach($array2 as $array) {
foreach($array1 as $get_data) {
if($array1['media_id'] == $get_data['media_id'] && $array1['userid'] == $get_data['userid']){
$get_result[] = //get_data true;
} else {
$get_result[] = //get_data false;
}
}
//get ID and username or show false value
}
最終的な答え
foreach($array2 as $array) {
$return = "false";
foreach($array1 as $get_data) {
if($array1['media_id'] == $get_data['media_id'] && $array1['userid'] == $get_data['userid']) {
$get_result[] = ['ID' => $get_data['ID'], 'username' => $get_data['username']];
$return = "true";
}
}
if($return = "false"){
echo false;
}
}
を必要とするものを有効なPHPの配列を入れてください、出力しない – hassan
はどこ 'foreachの()'であなたの試みですか? – Sean
あなたはこれまでに何を試しましたか? –