An array of add, delete, change,

Copyright: Original article reproduced please indicate the source https://blog.csdn.net/LQZ8888/article/details/90292666

 PHP can add, delete on an array, change,

    1. Setting Data
    2. Delete the specified element array, and maintain continuous index
    3. Specified elements of the array to make changes
    4. The existence of this element lookup data given value, the present output
    5. 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);

	 }

---------------------------------------------------------------------------------------------------------------------------------------------------------------

Guess you like

Origin blog.csdn.net/LQZ8888/article/details/90292666