仅从php中的关联数组获取值 [英] Get just the values from an associative array in php

查看:266
本文介绍了仅从php中的关联数组获取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的数组,如下所示:

I have a simple array like the following:


    array
      0 => string '101'
      1 => string '105'
      2 => string '103'

所需结果:


    array(101, 105, 103)

这可能吗?

推荐答案

是的,请使用 array_values .

Yes, use array_values.

array_values(array('0' => '101', '1' => '105', '2' => '103')); // returns array(101, 105, 103)

(感谢@MarkBaker)

(Thanks to @MarkBaker)

如果在原始数组和仅值"数组上使用var_dump,则如果键为数字键并从0开始递增,则输出看起来可能完全相同.

If you use var_dump on the original array and the "values only" array the output might look exactly the same if the keys are numerical and and ascending beginning from 0. Just like in your example.

如果键不是由数字组成,或者如果数字是随机",则输出将不同.例如,如果数组看起来像

If the keys are not consisting of numbers or if the numbers are "random" then the output would be different. For example if the array looks like

array('one' => '101', 'two' => '105', 'three' => '103')

使用array_values转换数组后,var_dump的输出看起来有所不同.

the output of var_dump looks different after converting the array with array_values.

这篇关于仅从php中的关联数组获取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆