PHP: Remove third item in 4 items comma list "1,2,3,4"
This question already has an answer here:
OK. How about using strpos and instr? Find the second comma and the third one.
$s = "1,2,3,4";
$array = explode(',', $s);
unset($array[2]);
$Arr = array_values($array);
print_r($Arr);
演示:https://eval.in/85585
怎么样,通过这个你不依赖于字符串的位置,而是可以通过价值消灭。
$s = "1,2,3,4";
$array = explode(",",$s);
$val = 3 ;
$key = array_search($val,$array);
if($key!==false){
unset($array[$key]);
}
echo implode(",",$array); // 1,2,4
链接地址: http://www.djcxy.com/p/30118.html
上一篇: 删除数组数组中的项目