PHP 中 in_array 函数的用法与注意项
in_array(value,array,type)
in_array 作用是用于查看 value 是否在 array 中存在,如果参数 value 是字符串,且 type 参数设置为 true,则搜索区分大小写。则 in_array 是 区分大小写 的。
有一点需要注意,当 array 中包含 value 的值,则返回 true; 但是,如果两者参数之间相等,则返回 false
例如:
$str = 'a';
$arr = array('a','b','c');
if( in_array($str,$arr) ){
echo "包含..";
}else{
echo '不包含..';
}
上面的代码运行后返回 “包含” 也就是 true,因为 $str 中有 $arr 的值、大小写也一样,最重要的是两者参数不相等!
再来,我们换个代码。
$str = array('a','b','c');
$arr = array('a','b','c');
if( in_array($str,$arr) ){
echo "包含..";
}else{
echo '不包含..';
}
这次就返回不包含了,所以我只能理解为 只能 $arr 中包含 $str,不能相等或超越。
那么修改下。
$str = array('a','b','c');
$arr = array(
array('a','b','c'),
array('d','e','f')
);
if( in_array($str,$arr) ){
echo "包含..";
}else{
echo '不包含..';
}
新手笔记,经供参考,如果错误,请指正!
相关文档:
防止以后忘掉,贴在这儿啦
function GetWeekDate($week,$year)
{
$timestamp = mktime(0,0,0,1,1,$year);
$dayofweek = date("w",$timestamp);
if( $week != 1)
&nb ......
PHP网站开发方案(开发新人必读)
一、开发成员
a)项目主管
b)页面美工
c)页面开发
d)服务端程序开发
e)系统与数据管理
f)测试与版本控制
二、 网站组开发简明流程
三、 开发工具与环境
a)服务器配置
i. W ......
<div id="time" align="center">time </div>
<script language="javascript">
function time1()
{
var now,n,y,r,h,m,s;
now=new Date();
n = now.getYear();
y = now.getMonth()+1;
r = now.getDate();
h = now.getHours();
m =now.getMinutes();
s = now.getSeconds();
......
php中substr的用法详解
php.net中关于substr的说明很简单:
start
If start is non-negative, the returned string will start at the start 'th position in string , counting from zero. For instance, in the string 'abcdef', the character at position 0 is 'a', the character at position 2 is 'c', and so for ......
在网站设计中我们经常会遇到需要多语言支持的情况。多语言系统按照支持的方式一般可分为两种:
1.支持多语言,但不支持多种语言的同时存在,也就是说要么是中文要么是英文或者其他,这在一些需要国际化支持的网页系统中经常用来,以便方便用户本地化。 2.支持多语言并可同时浏览不同语言版本的网页。今天我想讨 ......