PHP爆炸并设置为空字符串缺少的部分
发布时间:2020-12-13 18:06:51 所属栏目:PHP教程 来源:网络整理
导读:什么是完成以下任务的最佳方法. 我有这种格式的字符串: $s1 = "name1|type1"; //(pipe is the separator)$s2 = "name2|type2";$s3 = "name3"; //(in some of them type can be missing) 假设nameN / typeN是字符串,它们不能包含管道. 由于我需要逐步提取名
什么是完成以下任务的最佳方法.
我有这种格式的字符串: $s1 = "name1|type1"; //(pipe is the separator) $s2 = "name2|type2"; $s3 = "name3"; //(in some of them type can be missing) 假设nameN / typeN是字符串,它们不能包含管道. 由于我需要逐步提取名称/类型,我这样做: $temp = explode('|',$s1); $name = $temp[0]; $type = ( isset($temp[1]) ? $temp[1] : '' ); 有没有更容易(更聪明,更快)的方式,而不必做isset($temp [1])或count($temp). 谢谢! list($name,$type) = explode('|',s1.'|'); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |