Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Can anyone help me with this little problem please? I need to get (echo) the name, id and link from an array but after hours trying I have not been able, see the array below... Thank you in advanced.

            Array
            (
                [campaigns] => Array
                    (
                        [0] => Campaign Object
                            (
                                [name] => My name 1
                                [id] => 123456789012
                                [link] => 123456789012
                            )

                        [1] => Campaign Object
                            (
                                [name] => My name 2
                                [id] => 123456789012
                                [link] => 123456789012
                            )

                        [2] => Campaign Object
                            (
                                [name] => My name 3
                                [id] => 123456789012
                                [link] => 123456789012
                            )
                    )
            )
share|improve this question
2  
What have you tried so far? –  Tobias Kun Jul 27 '13 at 19:34

3 Answers 3

If you know which campaign you want, you can get it like this:

echo($data['campaigns'][0]->name);
echo($data['campaigns'][0]->id);
echo($data['campaigns'][0]->link);

If you want to loop through all of them, you could do something like this:

foreach ($data['campaigns'] as $item) {
    echo($item->name . "\n");
    echo($item->id . "\n");
    echo($item->link . "\n");
}

This is all a bit of a guess because we don't know what the Campaign class actually looks like - there may be a getName() method that you should be using instead of just accessing the name value directly, for example.

share|improve this answer
foreach ($array['campaigns'] as $key => $value){
    echo "Name: ".$value->name." ID: ".$value->id." Link: ".$value->link."\n";
}
share|improve this answer

Question is a little light on details to debug but have you tried this?

<?php echo $campaigns[0]->name; ?>
share|improve this answer
    
Yeah, sorry, I don't use PHP on a daily basis, will fix. –  Jared Beekman Jul 27 '13 at 19:40

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.