2

I would like to get the values of id and name inside this array.

Array
(
[data] => Array
    (
        [0] => Array
            (
                [id] => 238345159549706
                [members] => Array
                    (
                        [data] => Array
                            (
                                [0] => Array
                                    (
                                        [id] => 100001130889528
                                        [name] => Sy Cheeze
                                    )
                                [1] => Array
                                    (
                                        [id] => 100002616426665
                                        [name] => Chun Jenny
                                    )
                                    .......

I've tried using this foreach.

  foreach ($acquaintances as $acquaintance)
    {
      foreach ($acquaintance as $acquaint)
      {
        $acqID = $acquaint['id'];
        $acqName = $acquaint['name'];

        echo $acqName;
      }
    }

but nothing will be displayed. What would I do with my code? Any idea and suggestions please. Thank you!

1
  • check my answer bellow,and let me know if it is what you need Commented Sep 10, 2014 at 6:48

2 Answers 2

1
$array = array
   (
   array("bla",22,18),
   array("blaa",15,13),
   array("blaaa",5,2),
   array("blaaaa",17,15)
   );

for ($row = 0; $row <  4; $row++) {
   echo "<p><b>Row number $row</b></p>";
   echo "<ul>";
   for ($col = 0; $col <  3; $col++) {
     echo "<li>".$array[$row][$col]."</li>";
   }
   echo "</ul>";
}
Sign up to request clarification or add additional context in comments.

Comments

1

You can also access the indices directly in your foreach loop. Like this:

foreach($acquaintances['data'] as $acquaintance) {
    foreach($acquaintance['members']['data'] as $acquaint) {
        $acqID = $acquaint['id'];
        $acqName = $acquaint['name'];

        echo $acqName . '<br/>';
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.