php数组索引与键值操作技巧实例分析
本文实例讲述了php数组索引与键值操作技巧。分享给大家供大家参考。具体如下:
?
1 2 3 4 5 |
$array = array("a", "b","c"); //定义数组 $array[] = "Simon"; //增加一个新的数组元素 print_r($array); //输出数组 ?> |
?
1 2 3 4 5 |
$array = array("a", "b","c"); //定义数组 $array[9] = "Simon"; //增加一个新的数组元素 print_r($array); //输出数组 ?> |
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
//创建一个简单的数组 $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); ?> |
希望本文所述对大家的php程序设计有所帮助。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools