Home  >  Article  >  Backend Development  >  How to delete associative array in php

How to delete associative array in php

藏色散人
藏色散人Original
2020-07-22 09:07:312685browse

php method to delete an associative array: first create a PHP sample file; then define an array and add elements; finally use the unset function to delete the array.

How to delete associative array in php

phpAdd and delete associative arrays

The example is as follows:

<?php
//定义一个数组
$arr = array();
 
//添加元素
$arr[&#39;name&#39;]=&#39;baiduzhidao&#39;;
$arr[&#39;url&#39;]=&#39;baiduzhidaocom&#39;;
 
//删除某个元素
unset($arr[&#39;url&#39;]);
 
//删除数组
unset($arr);

unset Introduction:

unset — Release the given variable

Description

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

unset() Destroys the specified variable.

The behavior of unset() in a function will vary depending on the type of variable you want to destroy.

If you unset() a global variable in a function, only the local variable will be destroyed, and the variables in the calling environment will maintain the same value before calling unset().

Recommended: "PHP Tutorial"

The above is the detailed content of How to delete associative 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