php 修改关联数组的值_如何从PHP的关联数组中获取唯一值?

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 修改关联数组的值

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值