0

Here is a print_r() of my returned object:

    Array
(
    [0] => stdClass Object
        (
            [list_id] => 547009977
            [list_name] => Master List
            [list_type] => email
            [member_data] => Array
                (
                    [0] => stdClass Object
                        (
                            [name] => work_phone
                            [value] => 
                        )

                    [1] => stdClass Object
                        (
                            [name] => city
                            [value] => 
                        )

                    [2] => stdClass Object
                        (
                            [name] => restricted_since
                            [value] => 
                        )

                    [3] => stdClass Object
                        (
                            [name] => unsub_campaign_id
                            [value] => 
                        )

                    [4] => stdClass Object
                        (
                            [name] => title
                            [value] => 
                        )

                    [5] => stdClass Object
                        (
                            [name] => comments
                            [value] => 
                        )

                    [6] => stdClass Object
                        (
                            [name] => company_name
                            [value] => 
                        )

                    [7] => stdClass Object
                        (
                            [name] => Info
                            [value] => 
                        )

                    [8] => stdClass Object
                        (
                            [name] => address_hash
                            [value] => 
                        )

                    [9] => stdClass Object
                        (
                            [name] => hash
                            [value] => 2054ee9827
                        )

                    [10] => stdClass Object
                        (
                            [name] => country
                            [value] => 
                        )

                    [11] => stdClass Object
                        (
                            [name] => id
                            [value] => 45
                        )

                    [12] => stdClass Object
                        (
                            [name] => gender
                            [value] => 
                        )

                    [13] => stdClass Object
                        (
                            [name] => postalcode
                            [value] => 
                        )

                    [14] => stdClass Object
                        (
                            [name] => address_1
                            [value] => 
                        )

                    [15] => stdClass Object
                        (
                            [name] => create_date
                            [value] => 2013-07-15T15:31:35+00:00
                        )

                    [16] => stdClass Object
                        (
                            [name] => optin_status_last_updated
                            [value] => 2013-07-15T15:31:35+00:00
                        )

                    [17] => stdClass Object
                        (
                            [name] => Purchased
                            [value] => 
                        )

                    [18] => stdClass Object
                        (
                            [name] => marital_status
                            [value] => 
                        )

                    [19] => stdClass Object
                        (
                            [name] => optin_status
                            [value] => null
                        )

                    [20] => stdClass Object
                        (
                            [name] => last_updated
                            [value] => 2013-07-15T15:31:35+00:00
                        )

                    [21] => stdClass Object
                        (
                            [name] => address_2
                            [value] => 
                        )

                    [22] => stdClass Object
                        (
                            [name] => home_phone
                            [value] => 
                        )

                    [23] => stdClass Object
                        (
                            [name] => fax
                            [value] => 
                        )

                    [24] => stdClass Object
                        (
                            [name] => first_name
                            [value] => CoregTest
                        )

                    [25] => stdClass Object
                        (
                            [name] => bounce_campaign_id
                            [value] => 
                        )

                    [26] => stdClass Object
                        (
                            [name] => Page
                            [value] => 
                        )

                    [27] => stdClass Object
                        (
                            [name] => is_cass_certified
                            [value] => 0
                        )

                    [28] => stdClass Object
                        (
                            [name] => last_name
                            [value] => 
                        )

                    [29] => stdClass Object
                        (
                            [name] => restricted
                            [value] => 0
                        )

                    [30] => stdClass Object
                        (
                            [name] => mobile_phone
                            [value] => 
                        )

                    [31] => stdClass Object
                        (
                            [name] => email_address
                            [value] => coregtest@chrisjallen.com
                        )

                    [32] => stdClass Object
                        (
                            [name] => ip_address
                            [value] => 
                        )

                    [33] => stdClass Object
                        (
                            [name] => state
                            [value] => 
                        )

                )

        )

)

All I want to do is access the list_id in my php code. If I put it into a $result var:

 $result = $vr->searchListMembers( array(
        'session_id'  => $sid,
        'field_name'  => 'email_address',
        'field_value' => $email,
        'max_records' => 1
    ) );

I've tried

$result->list_id

and

$result[0]['list_id']

This is seemingly obvious but I'm missing something here.

Chris J Allen
  • 18,970
  • 20
  • 76
  • 114
  • 2
    list_id isn't in your code. – Woot4Moo Jul 17 '13 at 14:15
  • 2
    Try to `var_dump` the `$result` and have a look at the structure of the object. – Pieter Jul 17 '13 at 14:16
  • 2
    `$result[0]->list_id`? – gen_Eric Jul 17 '13 at 14:16
  • 1
    This is tagged [php], with [php] code. But the dump is javascript??? – PeeHaa Jul 17 '13 at 14:16
  • hmm..the console log is javascript ?! – bitWorking Jul 17 '13 at 14:16
  • ok, the image is a screenshot of the chromephp console output in chrome. The actual code is PHP. – Chris J Allen Jul 17 '13 at 14:19
  • 1
    @ChrisJAllen: Which language do you want to get the data in? How are you getting the data from one language to another? If you are trying to read it in PHP, a JavaScript console output is *not* helpful. Try to `var_dump($result)`. – gen_Eric Jul 17 '13 at 14:20
  • My script is PHP, the image i posted was a chromephp output. – Chris J Allen Jul 17 '13 at 14:21
  • @ChrisJAllen: What's `chromephp`? PHP has different data structures than JavaScript, so I think a `var_dump($result)` would be more helpful. – gen_Eric Jul 17 '13 at 14:21
  • 3
    Just show the raw PHP `var_dump` instead of something JS has already touched or you are making it hard for us to help you. – PeeHaa Jul 17 '13 at 14:23
  • 2
    In JavaScript, both arrays and objects can be accessed with `[]`. In PHP, this is not the case. In PHP, you use `[]` for arrays, and `->` for objects. Using `chromephp` won't tell you whether you have an object or an array in PHP. I suggest using `var_dump($result)` instead to debug. You may be able to access your value by: `$result[0]->list_id`. – gen_Eric Jul 17 '13 at 14:26
  • 3
    Well. loooky now. drop that chrome thing please or at least know what it does. Now that you have the actual output it should be fairly easy to do what you want. – PeeHaa Jul 17 '13 at 14:28

6 Answers6

2
$list_id = $result['list_id'];

however, list_id isn't in your code. So perhaps you meant session_id. Regardless, the syntax is:

array['key']
Woot4Moo
  • 23,987
  • 16
  • 94
  • 151
2

Try:

$list_id = $result[0]->list_id;
Lorenzo Marcon
  • 8,029
  • 5
  • 38
  • 63
1

ChromePHP doesn't seem like a very useful tool. This is because PHP and JavaScript have different data types/data structures, so a JavaScript console output won't tell you about how the object looks in PHP.

In JavaScript, objects and arrays can be accessed using []. In PHP, objects and arrays are accessed with different syntax. PHP arrays use [] and objects use ->.

If you want to debug PHP, I suggest you use var_dump (or print_r), this will show you if you have an array or an object. A JavaScript console will always show object, and is not very useful.

In your case, you need to access your element via:

$result[0]->list_id
gen_Eric
  • 223,194
  • 41
  • 299
  • 337
0

Omitting the fact that list_I'd isn't there it really depends on the return type of the searchListMember method you are using. If the returned var is an object you have to use ->list_id if its an array then it really about the structure but it should go like $result['list_id']

BVJ
  • 568
  • 4
  • 18
0

Try this!

print $result[0]->list_id;
Sergei Beregov
  • 738
  • 7
  • 19
0

If you do :

$result = $vr->searchListMembers( array(
        'session_id'  => $sid,
        'field_name'  => 'email_address',
        'field_value' => $email,
        'max_records' => 1
    ) );

$result is an Array.

So first you have to access the first element: $result[0]

Then, it is a stdClass object so you can access its properties with the -> operator:

$result[0]->list_id
gen_Eric
  • 223,194
  • 41
  • 299
  • 337
fluminis
  • 3,575
  • 4
  • 34
  • 47