技术笔记
当前位置:首页 > 商学院 > 技术笔记 > 正文内容

技术笔记

php在字符串型的参数表中新加参数删除参数查询参数

豫唐网络2023-03-07 08:091036

字符串型的参数表加入一个新参数,从字符串型的参数表中删除一个参数,在字符串参数值查找参数。

加入新参数应用案例

$array="1|2|3|4";
$name=AddNameInString($array,'5');
print_r($name);

输出结果为:

1|2|3|4|5

加入新参数函数

functionAddNameInString($s,$name)
{
$pl=$s;
$name=(string)$name;
$apl=explode('|',$pl);
if(in_array($name,$apl)==false){
$apl[]=$name;
}
$pl=trim(implode('|',$apl),'|');

return$pl;
}

删除一个参数应用案例

$array="1|2|3|4";
$name=DelNameInString($array,'1');
print_r($name);

输出结果为:

2|3|4

删除一个参数函数

functionDelNameInString($s,$name)
{
$pl=$s;
$name=(string)$name;
$apl=explode('|',$pl);
$count=count($apl);
for($i=0;$i<$count;$i++){
if($apl[$i]==$name){
unset($apl[$i]);
}
}
$pl=trim(implode('|',$apl),'|');

return$pl;
}

查找参数应用案例

$array="1|2|3|4";
$name=HasNameInString($array,'3');
print_r($name);

输出结果为:

1

查找参数函数

functionHasNameInString($s,$name)
{
$pl=$s;
$name=(string)$name;
$apl=explode('|',$pl);

returnin_array($name,$apl);
}

扫描二维码推送至手机访问。

版权声明:本文由汤阴县豫唐网络科技有限公司发布,如需转载请注明出处。

本文链接:https://www.ytecn.com/post/567.html

分享给朋友:

相关文章

php将编码转换为UTF8

php将编码转换为UTF8

主要用于编码不统一导致出现乱码的情况,此函数会自动监测非UTF8编码转成UTF8编码。functionConverCode($str){ $encode=mb_detect_encoding($st...

php获取网站在服务器中用的环境

php获取网站在服务器中用的环境

判断当前网站在服务器用的什么环境functionGetWebServer() { if(!isset($_SERVER['SERVER_SOFTWARE'])){ returnS...

php获取当前目录下文件夹列表

php获取当前目录下文件夹列表

获取当前目录下文件夹的名称应用案例$url="D:/wwwroot/ytecn.com/ui/"; $list=GetDirsInDir($url); print_r($lis...

获取当前目录下指定类型文件列表

获取当前目录下指定类型文件列表

获取当前目录下指定类型文件列表,比如或者txt文件,jpg文件等等。应用案例$url="D:/wwwroot/ytecn.com/txt/"; $list=GetFilesInD...

php获取文件权限

php获取文件权限

获取文件的权限,权限格式分为数值格式(如0644)和字符表达格式(如-rw-r--r--)两种数值格式应用案例$url="1.txt"; $name=GetFilePermsOc...

php从HTML中获取所有图片

php从HTML中获取所有图片

从HTML中获取所有图片。应用案例$txt='<p> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&a...