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

How to delete specified key name in array in php

青灯夜游
Release: 2023-03-09 09:08:01
Original
1972 people have browsed it

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(数组名称[键名]);
Copy after login

Example:

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

Output:

Array ( [1] => 1 [2] => 1 )
Copy after login

PHP unset() function

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

Syntax

void unset ( mixed $var [, mixed $... ] )
Copy after login

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!

Related labels:
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template