Home  >  Article  >  Backend Development  >  How to use unset() in php to delete a certain unit (key) in an array_PHP tutorial

How to use unset() in php to delete a certain unit (key) in an array_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:04:04803browse

How PHP uses unset() to delete a certain unit (key) in an array

This article mainly introduces how PHP uses unset() to delete a certain unit (key) in an array ) method, the example analyzes the usage skills of unset function when deleting array units. Friends in need can refer to it

The example in this article describes how PHP uses unset() to delete a certain unit (key) in an array. Share it with everyone for your reference. The specific analysis is as follows:

unset can delete either a variable or a unit in an array. But be aware that the array will not be reindexed.

Examples are as follows:

?

1

2

3

4

5

6

$arr = array("朝阳区","海淀区","西城区","东城区","丰台区");

unset($arr[3]);

echo "

";

print_r($arr);

?>

1 2

3

4

5

6

1

2

3

4

5

6

7

Array

(

[0] => 朝阳区

[1] => 海淀区

[2] => 西城区

[4] => 丰台区

)

$arr = array("Chaoyang District", "Haidian District", "Xicheng District", "Dongcheng District", "Fengtai District");

unset($arr[3]);

echo "
";

print_r($arr);?>
The output results are as follows:
?
1
2 3 4 5 6 7
Array ( [0] => Chaoyang District [1] => Haidian District [2] => Xicheng District [4] => Fengtai District )
I hope this article will be helpful to everyone’s PHP programming design. http://www.bkjia.com/PHPjc/966912.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/966912.htmlTechArticlephp uses unset() to delete a certain unit (key) in the array. This article mainly introduces the use of php The unset() method deletes a certain unit (key) in the array. An example analysis of the unset function in deleting...
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