Example Analysis of PHP Array Index and Key Value Operation Skills_PHP Tutorial

WBOY
Release: 2016-07-13 09:48:56
Original
1048 people have browsed it

Example analysis of php array index and key value operation skills

This article describes the example of php array index and key value operation skills. Share it with everyone for your reference. The details are as follows:

?

1

2

3

4

5

$array = array("a", "b","c"); //定义数组

$array[] = "Simon"; //增加一个新的数组元素

print_r($array); //输出数组

?>

1 2

3

4

5

1

2

3

4

5

$array = array("a", "b","c"); //定义数组

$array[9] = "Simon"; //增加一个新的数组元素

print_r($array); //输出数组

?>

$array = array("a", "b","c"); //Define array

$array[] = "Simon"; //Add a new array element

print_r($array); //Output 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);

?>

?>

1 2 3 4 5
$array = array("a", "b","c"); //Define array
<🎜>$array[9] = "Simon"; //Add a new array element<🎜> <🎜>print_r($array); //Output 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 <🎜>//Create a simple array<🎜> <🎜>$array = array(0=>1, 1=>2, 2=>3, 3=>4, 6=>5); print_r($array); //Now update the value of key 2 in the array to 100 $array[2] = 100; print_r($array); //Now add a key $array["X"] = 50; print_r($array); //Now remove all keys but keep the structure of the array itself foreach($array as $i => $value) { unset($array[$i]); } print_r($array); //Add another key $array[] = 25; print_r($array); //Use array_values ​​function for re-indexing $array = array_values($array); $array[] = 13; print_r($array); ?>
I hope this article will be helpful to everyone’s PHP programming design. http://www.bkjia.com/PHPjc/1020888.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1020888.htmlTechArticlePHP array index and key value operation skills example analysis This article describes the php array index and key value operation skills with examples. Share it with everyone for your reference. The details are as follows: ? 1 2 3 4 5 ?php $arra...
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!