Leon van der Veen
Leon van der Veen

Reputation: 1672

get value from array with objects

I've got an array like this:

Array (
  [0] => Mollie_Response Object (
     [@attributes] => Array ( [version] => v1 ) 
     [success] => true 
     [resultcode] => 10 
     [resultmessage] => Customer has the following payment methodes. 
     [services] => Mollie_Response Object ( 
        [ivr] => true 
        [minitix] => true 
        [psms] => true 
        [ideal] => true 
        [paysafecard] => false
     )
   )
 )

I want to get the value of [ideal] but I don't know how to do this.

What i've tried is this:

$response = $simplexml;

foreach( $response as $value ) 
{
    echo 'Test: '.$value[0].'<br>';
}

Response is this:

Test: true
Test: 10
Test: Customer has the following payment methodes.
Test: 

Any suggestions?

Upvotes: 0

Views: 101

Answers (2)

fedorqui
fedorqui

Reputation: 289725

I think identation helps a lot to check the fields:

Array ( [0] => 
  Mollie_Response Object ( 
      [@attributes] => Array ( [version] => v1 ) 
      [success] => true 
      [resultcode] => 10 
      [resultmessage] => Customer has the following payment methodes. 
      [services] => Mollie_Response Object ( 
          [ivr] => true 
          [minitix] => true 
          [psms] => true 
          [ideal] => true 
          [paysafecard] => false 
      )
  )
)

So now it is clear that you need to use $response[0]->services->ideal.

Upvotes: 1

jeroen
jeroen

Reputation: 91734

That would be something like:

$variable[0]->services->ideal

Upvotes: 5

Related Questions