dpbe81245 2011-07-13 16:39
浏览 34
已采纳

Php阵列搜索不起作用

Hi really need help here is my function.

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;
          }
}

then i am trying to do and if statement around it that isnt working.

$test = isdAuthorTrue( 102 );

echo $test;

if($test){

    echo "yes";

}else{

    echo "no";
}

i keep getting no what am i doing wrong???

  • 写回答

4条回答 默认 最新

  • douyun6781 2011-07-13 16:43
    关注

    You're getting "no" because array_search returns the key, in this case, 0. PHP evaluates that as false. Edit: didn't notice the strict comparison -- no it doesn't.

    Also, you're explicitly setting $key to 0...

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么