0

I'm a beginner and really need your help. I have the following data:

[1] => Array
             (
                 [category] => Professional sports team
                 [name] => MMA Academy Lebanon
                 [created_time] => 2014-02-27T08:26:50+0000
                 [id] => 145482752217243
             )

[2] => Array
            (
                [category] => Company
                [name] => AUB Rally Paper'11 - Team #2 - MEAB
                [created_time] => 2011-05-08T17:25:10+0000
                [id] => 184753811576654
            )

[3] => Array
            (
              [category] => Food/beverages
              [name] => SuperFresh Lebanon
              [created_time] => 2011-05-03T12:25:44+0000
              [id] => 118829648191256
            )

How can I extract and display only the name from each array using php? (note: I have many arrays so I need a code that will do the job regardless of how many arrays I have) I am a beginner so let your answer be as comprehensive and simple as possible

Thanks a lot!!

4
  • Have you given it a try? Commented Mar 17, 2014 at 8:23
  • If you're getting this from a database query, then modify your query to select only the column(s) that you need Commented Mar 17, 2014 at 8:23
  • If you're using PHP 5.5+, then use array_column() Commented Mar 17, 2014 at 8:23
  • Else, use array_map() like array_map( function($value) { return $value['name']; }, $myData); or a simple loop Commented Mar 17, 2014 at 8:25

2 Answers 2

2

Just loop it through using a foreach construct...

foreach($yourarray as $k=>$arr)
{
 echo $arr['name']."<br>";
}

Demo

Sign up to request clarification or add additional context in comments.

Comments

1

Try this,

foreach($yourarray as $arr)
{
 echo $arr['name']."<br/>";
}

1 Comment

If this question solved your problem, mark it as correct, it will help future users and is a simple way to thank @Roshna for helping you out

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.