Armory API Array issue

Hi

I have been trying to solve this problem for ages and with no luck :rolleyes:. Could someone please help me out. I can add stuff to the array list as well but when I print the arrayList out it prints out some random text.

http://sourceforge.net/p/wowarmoryapi/home/Home


$character = $armory->getCharacter('Byzantia');
print_r($character );

Array

#[pvp] => Array ( [brackets] => Array ( [ARENA_BRACKET_2v2] => Array ( [slug] => 2v2 [rating] => 1438 [weeklyPlayed] => 0 [weeklyWon] => 0 [weeklyLost] => 0
#[seasonPlayed] => 57 [seasonWon] => 29 [seasonLost] => 28 ) [ARENA_BRACKET_3v3] => Array ( [slug] => 3v3 [rating] => 0 [weeklyPlayed] => 0 [weeklyWon] => 0
#[weeklyLost] => 0 [seasonPlayed] => 0 [seasonWon] => 0 [seasonLost] => 0 ) [ARENA_BRACKET_5v5] => Array ( [slug] => 5v5 [rating] => 0 [weeklyPlayed] => 0
#[weeklyWon] => 0 [weeklyLost] => 0 [seasonPlayed] => 0 [seasonWon] => 0 [seasonLost] => 0 ) [ARENA_BRACKET_RBG] => Array ( [slug] => rbg [rating] => 576
#[weeklyPlayed] => 0 [weeklyWon] => 0 [weeklyLost] => 0 [seasonPlayed] => 4 [seasonWon] => 3 [seasonLost] => 1 ) ) ) [totalHonorableKills] => 46115 )

How do I print 2v2 or rbg Rating only.
Could someone help me out please, I will really appreciate it.

Thanks.

Just define the key you want. print_r just outputs the raw array/contents. You can print it out in a more readable way if you wrap your print_r in HTML < pre > tags.

But to answer your question:


print_r($character['ARENA_BRACKET_2v2']);

unfortunately doesn’t work :frowning:

Fatal error: Cannot use object of type Character as array in /home/technomaket/www.isneep.com/wow/test/index.php on line 39

Printed out in a more pretty way it looks like the result is:


Object (
    [pvp] => Array ( 
        [brackets] => Array ( 
            [ARENA_BRACKET_2v2] => Array ( 
                [slug] => 2v2 
                [rating] => 1438 
                [weeklyPlayed] => 0 
                [weeklyWon] => 0 
                [weeklyLost] => 0 
                [seasonPlayed] => 57 
                [seasonWon] => 29 
                [seasonLost] => 28 
            ) 
            [ARENA_BRACKET_3v3] => Array ( 
                [slug] => 3v3 
                [rating] => 0 
                [weeklyPlayed] => 0 
                [weeklyWon] => 0 
                [weeklyLost] => 0 
                [seasonPlayed] => 0 
                [seasonWon] => 0 
                [seasonLost] => 0 
            ) 
            [ARENA_BRACKET_5v5] => Array ( 
                [slug] => 5v5 
                [rating] => 0 
                [weeklyPlayed] => 0 
                [weeklyWon] => 0 
                [weeklyLost] => 0 
                [seasonPlayed] => 0 
                [seasonWon] => 0 
                [seasonLost] => 0 
            ) 
            [ARENA_BRACKET_RBG] => Array ( 
                [slug] => rbg [rating] => 576 
                [weeklyPlayed] => 0 
                [weeklyWon] => 0 
                [weeklyLost] => 0 
                [seasonPlayed] => 4 
                [seasonWon] => 3 
                [seasonLost] => 1 
            ) 
        ) 
    ) 
    [totalHonorableKills] => 46115 
)


Briefly looking at their API docs and the output you provided, it looks like they return an object that contains arrays. I personally don’t like working with mixed objects/arrays. I prefer to do one or the other but that’s just me.

You can try:


$character = $armory->getCharacter('Byzantia'); 

// For debugging purposes
echo "<pre>";
print_r($character);
echo "</pre>";

// Because they mix objects with arrays, which I personally don't like, we'll convert the object to an array with type casting, and trim off some of the outer layers
$brackets = (Array) $character['pvp']['brackets'];

// Print 2v2 info
echo "<pre>";
print_r($brackets['ARENA_BRACKET_2v2']);
echo "</pre>";

// Print RBG info
echo "<pre>";
print_r($brackets['ARENA_BRACKET_RBG']);
echo "</pre>";

See if that helps you any.

damn php I cant don’t understand what I am doing wrong… :nono:

Character Object
(
    [name:private] => Byzantia
    [region:private] => eu
    [realm:private] => Aegwynn
    [characterData:private] => Array
        (
            [lastModified] => 1407012712000
            [name] => Byzantia
            [realm] => Aegwynn
            [battlegroup] => Misery
            [class] => 5
            [race] => 1
            [gender] => 1
            [level] => 70
            [achievementPoints] => 9700
            [thumbnail] => aegwynn/217/62815449-avatar.jpg
            [calcClass] => X
            [guild] => Array
                (
                    [name] => BC Elite
                    [realm] => Aegwynn
                    [battlegroup] => Misery
                    [level] => 25
                    [members] => 291
                    [achievementPoints] => 855
                    [emblem] => Array
                        (
                            [icon] => 97
                            [iconColor] => ff092a5d
                            [border] => 0
                            [borderColor] => ff00317c
                            [backgroundColor] => ffffffff
                        )

                )

           [pvp] => Array
                (
                    [brackets] => Array
                        (
                            [ARENA_BRACKET_2v2] => Array
                                (
                                    [slug] => 2v2
                                    [rating] => 2237
                                    [weeklyPlayed] => 8
                                    [weeklyWon] => 3
                                    [weeklyLost] => 5
                                    [seasonPlayed] => 211
                                    [seasonWon] => 114
                                    [seasonLost] => 97
                                )

                            [ARENA_BRACKET_3v3] => Array
                                (
                                    [slug] => 3v3
                                    [rating] => 288
                                    [weeklyPlayed] => 0
                                    [weeklyWon] => 0
                                    [weeklyLost] => 0
                                    [seasonPlayed] => 8
                                    [seasonWon] => 3
                                    [seasonLost] => 5
                                )

                            [ARENA_BRACKET_5v5] => Array
                                (
                                    [slug] => 5v5
                                    [rating] => 0
                                    [weeklyPlayed] => 0
                                    [weeklyWon] => 0
                                    [weeklyLost] => 0
                                    [seasonPlayed] => 0
                                    [seasonWon] => 0
                                    [seasonLost] => 0
                                )

                            [ARENA_BRACKET_RBG] => Array
                                (
                                    [slug] => rbg
                                    [rating] => 0
                                    [weeklyPlayed] => 0
                                    [weeklyWon] => 0
                                    [weeklyLost] => 0
                                    [seasonPlayed] => 0
                                    [seasonWon] => 0
                                    [seasonLost] => 0
                                )

                        )

                )

            [totalHonorableKills] => 2692
        )
Fatal error: Cannot use object of type Character as array in /home/technomaket/www.isneep.com/wow/test/index.php on line 96

What happens if you:


$character = $armory->getCharacter('Byzantia');
echo "<pre>";
print_r($character->getBattlegrounds());
echo "</pre>";

According to your last output, it looks like it won’t be able to simply print_r the $character as he’s made a lot of the class properties private. So I’m assuming he’s provided accessor methods but the API documentation isn’t much in the way of documentation so I’m taking a guess that getBattlegrounds() is the one with the info you want.