<?php
$str1='1,11,12,15,18';
$textStr = '1';
$arr = explode(',', $str1);
if (in_array($textStr, $arr))
{
echo "true";
}
else
echo "false";
?>
$str1='1,11,12,15,18';
$textStr = '1';
$arr = explode(',', $str1);
if (in_array($textStr, $arr))
{
echo "true";
}
else
echo "false";
?>
解决方案 »
- php这两种写法的的区别是什么?
- 关于preg_match_all匹配的正则表达式问题
- 为什么不能读取sseion的内容
- phpcms 角色权限为什么不能用
- rawurlencode和urlencode分别应该在什么场合使用?请指点。
- PHP中如果修改ACCESS中记录
- 关于PHP上传CSV问题。。。。
- php如何解决同时大处理批量文件超时问题
- 请教用文本统计点击数并按点击数排序的问题!(属于编程问题吧)
- The IMAP module does not seem to be installed on this PHP setup, please see NOCC's documentation.
- 熬了一夜也没想通的问题,在线等
- apache内存不能释放,一直涨到停止,什么解决
$str1='1,11,12,15,18';
$str2='12';
$textStr = '1';/*
实际正则是 '/(^[^0-9,]1,|,1,|,1[^0-9,]$/ 按照给出格式只有3种可能
1开头 2中间 3最后 所以只要匹配3种可能中的一个,就找到了相应的位置
*/
preg_match_all('/^[^0-9,]*'.$textStr.',|,'.$textStr.',|,'.$textStr.'[^0-9,]*$/', $str1, $str1Arr);preg_match_all('/^[^0-9,]*'.$textStr.',|,'.$textStr.',|,'.$textStr.'[^0-9,]*$/', $str2, $str2Arr);print_r($str1Arr);print_r($str2Arr);
?>