嗨,这里真的需要帮助,这是我的职能。
function isdAuthorTrue( $post_id ) {
$coauthors = get_post_meta( $post_id, "coAuthors" );
print_r($coauthors);
// print_r output Array ( [0] => 78 )
$key = array_search( 78, $coauthors );
$key = 0;
if($key !== false) {
return true;
} else {
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
然后我正在尝试做,如果围绕它的声明不起作用。
$test = isdAuthorTrue( 102 );
echo $test;
if($test){
echo "yes";
}else{
echo "no";
}
Run Code Online (Sandbox Code Playgroud)
我一直不明白我做错了什么???
您得到“否”,因为 array_search 返回键,在本例中为0。PHP 将其评估为false. 编辑:没有注意到严格的比较——不,没有。
此外,您明确设置$key为0...
| 归档时间: |
|
| 查看次数: |
2793 次 |
| 最近记录: |