0

I work on SendinBlue Api to recover statistics of my email campaigns. But the probleme is that I can't recover one of the object because there in a "." in the name of the object.

Here the json :

[statistics] => stdClass Object
                 (
                   [statsByDomain] => stdClass Object
                      (
                        [gmail.com] => stdClass Object
                             (
                               [uniqueClicks] => 10
                               [clickers] => 130
                               [complaints] => 130
                               [sent] => 130
                               [softBounces] => 59
                               [hardBounces] => 48
                               [uniqueViews] => 59
                               [unsubscriptions] =>89
                               [viewed] => 130
                               [delivered] => 130
                             )

                       )

               )

But I don't understand how can I recover the object of "statsByDomain". Someone can help me ?

The first part work well, but know I want to recover all the object contain in "statsByDomain" and I don't know how to do that.

Now I can recover one object by one :

foreach($campagnes as $campagne){

    echo "<br> UniqueClicks : " .$campagne['statistics']-> statsByDomain -> {'gmail.com'}  -> uniqueClicks;
    echo "<br> UniqueClicks : " .$campagne['statistics']-> statsByDomain -> {'gmail.fr'}  -> uniqueClicks;
}
anono
  • 35
  • 6

2 Answers2

0

In fact, it works well:

foreach($campagnes  as $campagne){
    echo $campagne["statistics"]->statsByDomain->{"gmail.com"}->uniqueClicks.PHP_EOL;
}

Demo

EDIT

foreach($campagnes  as $campagne){
    foreach($campagne["statistics"]->statsByDomain as $key=>$obj){
       // $key = gmail.com or web.com or web2.org
        echo $obj->uniqueClicks.PHP_EOL; 
    }
    echo PHP_EOL;
}

Demo

Aksen P
  • 4,564
  • 3
  • 14
  • 27
0

In this code snippet $campagnes contains your data and it should be clear how to extract any part of it:

$campagnes = (object)array(
        'statistics' => (object)array(
            'statsByDomain' => (object)array(
                'gmail.com' => (object)array(
                    'uniqueClicks' => 10,
                    'clickers' => 130,
                    'complaints' => 130,
                    'sent' => 130,
                    'softBounces' => 59,
                    'hardBounces' => 48,
                    'uniqueViews' => 59,
                    'unsubscriptions' =>89,
                    'viewed' => 130,
                    'delivered' => 130
                )
            )
        )
    );

    var_dump($campagnes);

    var_dump($campagnes->statistics->statsByDomain-> {"gmail.com"}->uniqueClicks);
luigif
  • 544
  • 4
  • 8