Copyright: Original article reproduced please indicate the source https://blog.csdn.net/LQZ8888/article/details/90292666
PHP can add, delete on an array, change,
-
- Setting Data
- Delete the specified element array, and maintain continuous index
- Specified elements of the array to make changes
- The existence of this element lookup data given value, the present output
- Specified element can be inserted according to the specified index
public function index4()
{
echo "源数据"."</br>";
$arr = ['1','2','3','4','5','6','7','8','9','10','11','12','13','14'];
print_r($arr);
echo "</br>"."删除数据2"."</br>";
// 删除一个数
// unset($arr['2']);
array_splice($arr,1,1);
print_r($arr);
echo "</br>"."修改下标5"."</br>";
$arr['5'] = '99';
print_r($arr);
echo "</br>"."查找数据6"."</br>";
if (in_array("6",$arr))
{
$n = array_search("6",$arr);
print_r($arr[$n]);
}
else
{
echo "没有此数据";
}
echo "</br>"."插入下标位置6"."</br>";
$list = array('88','99');
$n = 6 ;//插入的位置
array_splice($arr,$n,0,$list);
print_r($arr);
}
---------------------------------------------------------------------------------------------------------------------------------------------------------------