PHP的array_search返回第一个元素的0? [英] php array_search returning 0 for the first element?

查看:234
本文介绍了PHP的array_search返回第一个元素的0?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个代码

$restaurant = array('/restaurant_pos/', '/bar_nightclub_pos/')
$current_page = $_SERVER['REQUEST_URI'];

if (array_search($current_page, $restaurant)) {
    echo "KEEP ME";
}

问题是array_search返回0,因为'/restaurant_pos/'是​​导致if失败的数组中的第一个元素...有关如何检查值是否在数组中而不会失败的任何想法第一个元素

the problem is the array_search is returning 0 because '/restaurant_pos/' is the first element in the array which is causing the if to fail...any ideas on how to check if the value is in the array without failing on the first element

推荐答案

if (array_search($current_page, $restaurant) !== FALSE ) {
    echo "KEEP ME";
}

手册链接: http://php.net/manual/zh/function .array-search.php

这篇关于PHP的array_search返回第一个元素的0?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆