有必要删除部分数组.这是一个数组的例子:
Array ( [0] => one [1] => two [2] => three [3] => four [4] => five )
Run Code Online (Sandbox Code Playgroud)
变量可以基于数组中的以下值之一.建议有'三'.需要取一个,两个,其他一切都删除.
有没有标准方法,或者不需要使用循环的好解决方案?
您可以使用array_splice为
$input = array("red", "green", "blue", "yellow");
array_splice($input, 1, -1);
// $input is now array("red", "yellow")
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1125 次 |
| 最近记录: |