Detailed explanation of PHP key value operations

小云云
Release: 2023-03-22 19:54:02
Original
2689 people have browsed it

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);  

?>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template