How to remove key name from php array

青灯夜游
Release: 2023-03-09 21:26:01
Original
2082 people have browsed it

In php, you can use the array_values() function to remove the key in the array, the syntax format is "array_values(array)". The array_values() function returns an array containing all the key values ​​​​in the given array, but does not retain the key names; the returned array will use numeric keys.

How to remove key name from php array

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

php remove the key name from the array and return All key values ​​in the array

<?php
$a=array("Name"=>"Peter","Age"=>"41","Country"=>"USA");
print_r(array_values($a));
?>
Copy after login

Output:

Array ( [0] => Peter [1] => 41 [2] => USA )
Copy after login

Description:

rray_values() function returns An array containing all key values ​​in the given array, but without retaining key names.

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

Syntax

array_values(array)
Copy after login

Return value

  • Returns an array containing all the values ​​in the array.

Recommended study: "PHP Video Tutorial"

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