从多维对象数组中检索键



我正在处理一个多维对象/数组,并希望检索标记为confirm_enabled的键的值并将其存储在变量中。下面是对象:

object(stdClass)#361 (2) { ["id"]=> string(1) "1" ["meta"]=> string(475) "{"feed_name":"Default Feed","auto_respond":"0","push_Salesforce":"0","lookup_enabled":"1","confirm_enabled":"1","voterdata_mapped_fields*":"9","voterdata_mapped_fields*":"10","voterdata_mapped_fields_*":"11","voterdata_mapped_fields_*":"","voterdata_mapped_fields_*":"","voterdata_mapped_fields_*":"13","voterdata_mapped_fields_*":"6"}" }

有人知道我该怎么做吗?

试试这个:

$retrieve = (theVariable)->meta->confirm_enabled;
print_r($retrieve);

或者如果你想把所有这些都变成一个数组使用这个:

$a =  json_encode((the_fetch_data)) // insert where you get the data
$b = json_decode($a) // then decode to make this all an array
print_r($b['meta']['confirm_enabled']); //show data

我明白了!在尝试解析之前,我忘记了json_decode()。我查询我的数据库检索对象,这是存储在$meta。从那里,我只做了以下操作:

$meta = json_decode( $meta[0]->meta );
$confirm_enabled = intval( $meta->confirm_enabled );

我希望这能帮助到别人!

相关内容

  • 没有找到相关文章

最新更新