PHP,如何从数组中回显特定的对象数据?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5054520/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 16:40:14  来源:igfitidea点击:

PHP, how to echo specific object data from array?

phparraysecho

提问by user6291275

I use this in wordpress:

我在wordpress中使用这个:

$arr=get_post_meta($post->ID, false);

I receive this array:

我收到这个数组:

Array (
[_edit_last] => Array ( [0] => 2)
[year_completed] => Array ( [0] => 2010 )
[designers] => Array ( [0] => )
[developers] => Array ( [0] => )
[producers] => Array ( [0] => )
[_edit_lock] => Array ( [0] => 1298159324 )
[name_en] => Array ( [0] => game 1)
[name_et] => Array ( [0] => game 2 )
[friends_meta] => Array ( [0] => )
)

How do I echo (no for, foreach, etc please) name_en data? Even print_r ($arr->name_en);doesn't work... I suppose it has to be something like - echo $arr->name_en[0];???

我如何回显(请不要 for、foreach 等)name_en 数据?即使print_r ($arr->name_en);不起作用......我想它必须是这样的 - echo $arr->name_en[0];???

回答by Felix Kling

It is an array or arrays, so:

它是一个或多个数组,所以:

print_r($arr['name_en']);

or if you only want to get the data:

或者如果您只想获取数据:

echo $arr['name_en'][0];

The ->operator is for accessing properties of objects.

->运算符用于访问对象的属性。

回答by tdammers

echo $arr['name_en'][0]should work.

echo $arr['name_en'][0]应该管用。

回答by Shuhad zaman

this should work

这应该有效

echo $arr[0]['year_completed'];

echo $arr[0]['designers'];

etc

等等