This article mainly shares with you the detailed explanation of PHP key value operations, mainly in the form of code. I hope it can help you.
<?php //创建键值对应的数组 $array = array(0=>1, 1=>2, 2=>3, 3=>4, 6=>5); print_r($array); //把数组中键为3的值更新为300 $array[3] = 300; print_r($array); //现在添加一个键和值 $array["B"] = 80; print_r($array); //现在删除所有键和值(但保持数组原本的结构) foreach($array as $i => $value) { unset($array[$i]); } print_r($array); //再添加一个键 $array[] = 90; print_r($array); //使用array_values对数组重新索引 $array = array_values($array); $array[] = 18; print_r($array); ?>
Related recommendations:
php array index and key value operation skills example analysis_PHP tutorial
The above is the detailed content of Detailed explanation of PHP key value operations. For more information, please follow other related articles on the PHP Chinese website!