Home > php教程 > php手册 > body text

php数组索引与键值操作技巧实例分析,操作技巧实例分析

WBOY
Release: 2016-06-13 09:00:10
Original
940 people have browsed it

php数组索引与键值操作技巧实例分析,操作技巧实例分析

本文实例讲述了php数组索引与键值操作技巧。分享给大家供大家参考。具体如下:

<&#63;php 
$array = array("a", "b","c"); //定义数组 
$array[] = "Simon"; //增加一个新的数组元素 
print_r($array); //输出数组 
&#63;> 

Copy after login
<&#63;php 
$array = array("a", "b","c"); //定义数组 
$array[9] = "Simon"; //增加一个新的数组元素 
print_r($array); //输出数组 
&#63;> 

Copy after login
<&#63;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); 
&#63;>

Copy after login

希望本文所述对大家的php程序设计有所帮助。

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template