Home >Backend Development >PHP Tutorial >PHP array index and key value operation skills example analysis, operation skills example analysis_PHP tutorial
This article describes the PHP array index and key value operation skills with examples. Share it with everyone for your reference. The details are as follows:
<?php $array = array("a", "b","c"); //定义数组 $array[] = "Simon"; //增加一个新的数组元素 print_r($array); //输出数组 ?>
<?php $array = array("a", "b","c"); //定义数组 $array[9] = "Simon"; //增加一个新的数组元素 print_r($array); //输出数组 ?>
<?php //创建一个简单的数组 $array = array(0=>1, 1=>2, 2=>3, 3=>4, 6=>5); print_r($array); //现在把数组中键为2的值更新为100 $array[2] = 100; print_r($array); //现在添加一个键 $array["X"] = 50; print_r($array); //现在删除所有键,但保持数组本身的结构 foreach($array as $i => $value) { unset($array[$i]); } print_r($array); //再添加一个键 $array[] = 25; print_r($array); //使用array_values函数进行重新索引 $array = array_values($array); $array[] = 13; print_r($array); ?>
I hope this article will be helpful to everyone’s PHP programming design.