//1. 判断是否包含字符
function checkstr($substr, $str)
{
$tmparray = explode(",",$str);
if(in_array($substr, $tmparray)){
return true;
} else{
return false;
}
}
echo checkstr(123, '11,12,123,1234'); // 1
echo checkstr(23, '11,12,123,1234'); //
2. 删除一个数组中存在于另一个数组的元素
$ids = '2,15';
$ids = '5,62,8,2,3,44,15,67';
$arr1=explode(',',$ids);
$arr2=explode(',',$nids);
$arr1=array_diff($arr1,$arr2);
var_dump($arr1);
echo implode(",", $arr1);
/*
执行结果:
array(6) {
[0]=>
string(1) "5"
[1]=>
string(2) "62"
[2]=>
string(1) "8"
[4]=>
string(1) "3"
[5]=>
string(2) "44"
[7]=>
string(2) "67"
}
5,62,8,3,44,67
*/
3. 打印输出变量到TXT文件
$nsql = Db::name('table')->getLastSql();
$myfile = fopen("log.txt", "a+") or die("Unable to open file!");
fwrite($myfile, "id: ".$res['id']."\n");
fwrite($myfile, "ids: ".$res['ids']."\n");
fwrite($myfile, "nsql:".$nsql."\n");
fclose($myfile);