2

I have the following array that is in PHP (this is a print_r() output).

I'm currently struggling to loop through this data - need to be able to process each part and access the values in each array item. How can I do this.

I've tried the following unsuccessfully...

foreach (array as $key => $value) {
 echo $key;
}

enter image description here

2
  • 3
    you have objects there not arrays, perhaps you should try parsing your json in an associative way with json_decode($string, true) Commented Jul 10, 2013 at 6:27
  • 1
    It is an array, but the members are objects. Commented Jul 10, 2013 at 6:28

2 Answers 2

4

Try this. Since you have an array of objects, you should be able to access each object property using ->

foreach($array as $value) {
    echo $value -> userid;
}

It should echo out all the user id in that array of objects

0
4

You have an array of objects, so try something like this:

<?php
foreach ($array as $value) {
    echo $value->userid;
    echo $value->action;
    echo $value->photo_name;
}

You don't need the $key since you're not using it in the loop. Each iteration will put the object in the $value variable, on which you can access it's properties.

1
  • thankyou... your answer is also correct... voted up... cheers Commented Jul 10, 2013 at 6:41

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.