php 修改关联数组的值
Given an array with keys, values and we have to create an array with the only values.
给定具有键,值的数组,我们必须创建具有唯一值的数组。
从数组中获取唯一值 (Getting the only values from an array)
To extract the only values from an associative array, we use array_values() function, it returns a new arrays with numeric indexes (starting from 0 index) and values.
为了从关联数组中提取唯一的值,我们使用array_values()函数 ,它返回一个带有数字索引(从0索引开始)和值的新数组。
Syntax:
句法:
array_values(array);
It accepts an array and returns a new array having only values from given array.
它接受一个数组,并返回一个仅包含给定数组中值的新数组。
PHP代码从关联数组中获取唯一值 (PHP code to get the only values from an associative array)
<?php
//array with keys and values
$arr = array("name" => "Amit", "age" => 21, "Gender" => "Male");
//creating a new array with values of $arr
$new_arr = array_values($arr);
//printing new array
print_r ($new_arr);
?>
Output
输出量
Array
(
[0] => Amit
[1] => 21
[2] => Male
)
翻译自: https://www.includehelp.com/php/get-the-only-values-from-an-associative-array-in-php.aspx
php 修改关联数组的值