Home  >  Article  >  Backend Development  >  How to delete specified key name in array in php

How to delete specified key name in array in php

青灯夜游
青灯夜游Original
2021-03-31 18:50:041872browse

In PHP, you can use the unset() function to delete the specified key name in the array, the syntax format is "unset(array name[key name]);". The unset() function can destroy a given variable, and its behavior will vary depending on the type of variable you want to destroy.

How to delete specified key name in array in php

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

php deletes the array specified key name

In PHP, you can use the unset() function to delete the specified key name in the array. The syntax format is as follows:

unset(数组名称[键名]);

Example:

<?php
$data=array ("0"=>1,"1"=>1,"2"=>1);
unset($data[0]);	
print_r($data);  
?>

Output:

Array ( [1] => 1 [2] => 1 )

PHP unset() function

unset() function is used to destroy the given variable.

Syntax

void unset ( mixed $var [, mixed $... ] )

Parameter description:

  • $var: variable to be destroyed.

Return value: No return value.

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to delete specified key name in array in php. 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