after the edit i guess you want more than 2 ?
so ..
foreach ($new as $n){
echo $n['post'].',';
}
Domanda
How do I get the value of an associative array using its key. For example, I have:
$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"
)
);
Now I want to get the value of post
. That means I want to get echoed anything, something
. How do I accomplish this? I tried a way but that's not working. Example;
print_r($new['post']);
I also tried echo $new['post'];
but doesn't work. Please help
Soluzione
after the edit i guess you want more than 2 ?
so ..
foreach ($new as $n){
echo $n['post'].',';
}
Altri suggerimenti
You can do like this
foreach($new as $key => $value){
echo $value['post']."<br/>";
}
Incase you don't need the key:
foreach($new as $value){
echo $value['post']."<br/>";
}
PHP >= 5.5.0
foreach(array_column($new, 'post') as $post) {
echo $post;
}