如何使用其键获取关联数组的值。例如,我有:
$new = array(
array(
"post" => "anything",
"newt" => "Nothing"
),
array(
"post" => "something",
"newt" => "Filthy"
),
array(
"post" => "one value",
"newt" => "normal"
),
array(
"post" => "two value",
"newt" => "happy"
),
array(
"post" => "Three",
"newt" => "more"
)
);
现在我希望得到post
的值。这意味着我希望得到回应anything, something
。我该如何做到这一点?我尝试了一种方法但是没有用。实施例;
print_r($new['post']);
我也试过了echo $new['post'];
但是没有用。请帮忙
答案 0 :(得分:1)
编辑后我猜你想要超过2个?
所以..
foreach ($new as $n){
echo $n['post'].',';
}
答案 1 :(得分:1)
你可以这样做
foreach($new as $key => $value){
echo $value['post']."<br/>";
}
如果您不需要密钥:
foreach($new as $value){
echo $value['post']."<br/>";
}
答案 2 :(得分:1)
PHP&gt; = 5.5.0
foreach(array_column($new, 'post') as $post) {
echo $post;
}