我想要得到的是..
我不知道check_mobile_exists( $mobiles, $electronics )
这个函数是否一直返回 true。当 $electronics 密钥列表中存在 $mobile 数组密钥时,我希望为真,如果不存在,则为假。在此结果的基础上,我正在循环发布结果。但正如我所说,该函数在每次迭代时都返回 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;