剥离在它只有一个项目的数组不用循环直通它,不知道它的索引 [英] strip array with only one item in it without looping thru it and not knowing its index

查看:104
本文介绍了剥离在它只有一个项目的数组不用循环直通它,不知道它的索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Array
(
    [2] => stdClass Object
        (
            [name] => test-song-poll-03
            [description] => test-song-poll-03
            [created_at] => 2014-05-02T23:19:06Z
            [count] => stdClass Object
                (
                    [approved] => 26638
                    [pending] => 0
                    [rejected] => 36923
                    [total] => 63561
                )

            [tpm] => 47
            [approved_tpm] => 9
            [pct] => 2
        )

)

我有一个使用array_filter的函数,它返回你所看到的上面。它不仅将数组中返回一个对象。我不知道该数组的索引将是什么,但我知道只会有数组中的一个项目。是否有剥离下来阵列中的函数,只是返回它的内容,因为我不需要只有一个项目的数组中了。

I have a function that uses array_filter and it returns what you see above. It will only return one object within the array. I do not know what the array index will be, but I know there will only be one item in the array. Is there an array function that strips down the array and just returns the content of it, since I don't need an array with just one item in it.

推荐答案

您应该使用:

$x = array_values($yourArrayName);
echo $x[0];

您也可以使用:

echo current($yourArrayName);

这篇关于剥离在它只有一个项目的数组不用循环直通它,不知道它的索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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