Home  >  Article  >  Backend Development  >  How to remove key name from php array

How to remove key name from php array

青灯夜游
青灯夜游Original
2021-05-24 17:34:532075browse

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));
?>

Output:

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

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)

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!

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