从 PHP stdClass 获取属性名称 [英] Get property names from PHP stdClass
本文介绍了从 PHP stdClass 获取属性名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个如下所示的数组对象:
I have an array object that looks like:
$inDatabase = Array
(
[0] => stdClass Object
(
[abc@gmail.com] => Array
(
)
)
[1] => stdClass Object
(
[xyz@gmail.com] => Array
(
)
)
)
如何将电子邮件地址推送到新阵列上?我尝试了以下方法:
How do I push email addresses onto a new array? I tried the following:
$innerKeys =[];
$temp=[];
for($i=0;$i<2;$i++){
$temp = array_keys($inDatabase[$i])
//so I thought $temp[0] would have the email address but $temp is null.
array_push($innerKeys,$temp[0]);
}
推荐答案
array_keys()
用于数组.要将对象属性转换为数组,请使用 get_object_vars()
.所以你想要
array_keys()
is for arrays. To turn the object properties into an array, use get_object_vars()
. So you want
$temp = array_keys(get_object_vars($inDatabase[$i]));
这篇关于从 PHP stdClass 获取属性名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文