Home  >  Article  >  Backend Development  >  Detailed explanation of PHP key value operations

Detailed explanation of PHP key value operations

小云云
小云云Original
2018-03-30 15:33:552619browse

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!

Statement:
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
Previous article:PHP coding standardsNext article:PHP coding standards