PHP |阵列获取价值和关键 [英] PHP | Array get both value and key

查看:120
本文介绍了PHP |阵列获取价值和关键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个PHP数组,它看起来像:

  $阵列=阵列

    [teamA] =>排列
    (
        [188555] => 1
    )
    [teamB] =>排列
    (
        [188560] => 0
    )
    [现状] =>排列
    (
        [0] =>上
    )

在上面的例子中,我可以使用下面的code:

 回声$阵列[teamA] [188555]。

要获得价值1。

现在的问题,有没有办法让在188555同样的方式;

的键teamA,teamB和状态总是阵列中的相同。 ALSE既teamA和teamB阵列保持总是只有一个记录。

那么,有没有办法让只有数组teamA和的第一个元素的关键teamB?


解决方案

 回声array_keys($数组['teamA'])[0];

这个 从官方PHP站点的详细信息。

I have a PHP array that looks like that:

$array = Array
(
    [teamA] => Array
    (
        [188555] => 1
    )
    [teamB] => Array
    (
        [188560] => 0
    )
    [status] => Array
    (
        [0] => on
    )
)

In the above example I can use the following code:

echo $array[teamA][188555];

to get the value 1.

The question now, is there a way to get the 188555 in similar way;

The keys teamA, teamB and status are always the same in the array. Alse both teamA and teamB arrays hold always only one record.

So is there a way to get only the key of the first element of the array teamA and teamB?

解决方案

echo array_keys($array['teamA'])[0];

Refer this for detailed information from official PHP site.

这篇关于PHP |阵列获取价值和关键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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