Home > Backend Development > PHP Problem > How to delete the key value of an array in php

How to delete the key value of an array in php

王林
Release: 2023-03-02 15:40:02
Original
3625 people have browsed it

The method to delete the key value of an array in php is: you can use the array_values() function to achieve this. This function returns an array containing all the values ​​in the array. The returned array will use numeric keys, starting from 0 and increasing by 1. Function syntax: [array_values(array)].

How to delete the key value of an array in php

#If you want to delete the key value of the array, you can use the array_values() function to achieve this. Let's introduce this function below.

(Recommended tutorial: php tutorial)

Function introduction:

array_values() function returns an array containing all the values ​​in the array.

Note: The returned array will use numeric keys, starting from 0 and increasing by 1.

Syntax:

array_values(array)
Copy after login

Parameter description:

  • ##array Required. Specifies an array.

Code implementation:

<?php
$arr = array(&#39;key1&#39;=>&#39;value1&#39;,&#39;key2&#39;=>&#39;value2&#39;,&#39;key3&#39;=>&#39;value3&#39;);
$arr2 = array_values($arr);
print_r($arr2);
?>
Copy after login

Output result:

array(&#39;0&#39;=>&#39;value1&#39;,‘1&#39;=>&#39;value2&#39;,&#39;2&#39;=>&#39;value3&#39;);
Copy after login

The above is the detailed content of How to delete the key value of an array in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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