私が取得しようとしているのは..
check_mobile_exists( $mobiles, $electronics )
この関数が常に true を返すかどうかはわかりません。$electronics キー リストに $mobile 配列キーが存在する場合は true、存在しない場合は false が必要です。この結果に基づいて、投稿結果をループしています。しかし、私が言ったように、関数はすべての反復で true を返します。私が今何をすべきかを提案してくれる人はいますか?
function check_mobile_exists( $mobiles, $electronics ) {
foreach( $mobiles as $mobile => $price ) {
if( array_key_exists( $mobile, $electronics ) ) {
return true;
}
return false;
}
}
$mobiles = array(
'iPhone' => '$350',
'tablet' => '$100',
'samsung' => '$200',
'walton' => '$60'
);
$electronics = array(
'iPhone' => 'OK',
'tablet' => 'will do',
'walton' => 'No need'
);
while( have_posts() ): the_post();
if( check_mobile_exists( $mobiles, $electronics ) ){ // returning only true on every iterating
echo get_the_title() .' do something....<br />';
} else {
echo 'Do another....';
}
endwhile;