0

I asked this question few months ago but at that time i needed to pull just one membership level, now i need to pull every level name, here is array:

Array
(
  [success] => 1
  [member] => Array
  (
    [0] => Array
    (
      [Levels] => Array
      (
        [1391447566] => stdClass Object
        (
          [Level_ID] => 1391447566
          [Name] => Team Membership
          [Cancelled] => 
          [CancelDate] => 
          [Pending] => 
          [UnConfirmed] => 
          [Expired] => 
          ExpiryDate] => 1397266537
          [SequentialCancelled] => 
          [Active] => 1
          [Status] => Array
          (
            [0] => Active
          )
          [Timestamp] => 1394588137
          [TxnID] => WL-1-1391447566
        )

        [1391540448] => stdClass Object
        (
          [Level_ID] => 1391540448
          [Name] => Gold Training Membership
          [Cancelled] => 
          [CancelDate] => 
          [Pending] => 
          [UnConfirmed] => 
          [Expired] => 
          [ExpiryDate] => 1396642789
          [SequentialCancelled] => 
          [Active] => 1
          [Status] => Array
          (
            [0] => Active
          )

          [Timestamp] => 1393967989
          [TxnID] => WL-1-1391540448
        )

        [1391540567] => stdClass Object
        (
          [Level_ID] => 1391540567
          [Name] => Platinum Training Membership
          [Cancelled] => 
          [CancelDate] => 
          [Pending] => 
          [UnConfirmed] => 
          [Expired] => 
          [ExpiryDate] => 1397302237
          [SequentialCancelled] => 
          [Active] => 1
          [Status] => Array
          (
            [0] => Active
          )

          [Timestamp] => 1394623837
          [TxnID] => WL-1-1391540567
        )

      )

      [PayPerPosts] => Array
      (
      )

    )

  )

  [supported_verbs] => Array
  (
    [0] => GET
    [1] => PUT
    [2] => DELETE
  )

)

What I need is to pull Name of Level which is inside an object that has diffrent number every time and add it to an array which i need to save in DB. One solution, just to pull info, wass:

foreach ($response["member"][0]["Levels"] AS $level_key => $level_val) {
$level_name = $level_key->Name;
    echo 'Name: '.$level_name;
}

but its not pulling anything, just echoing "name" 3 times.

This was the code i used to pull only one name:

$levels = $response["member"][0]["Levels"];
$firstLevel = array_shift(array_values($levels));
$membership = $firstLevel->Name;

Thanks!

1
  • 1
    $level_name = $level_key->Name; should be $level_name = $level_val->Name ; Commented Mar 12, 2014 at 11:41

1 Answer 1

5

Just try with:

$level_name = $level_val->Name;

$level_key is an integer value with level ID (?). $level_val is your level object with data.

Sign up to request clarification or add additional context in comments.

1 Comment

@GoranJakovljevic Remember to accept this answer with the tick on the left and your other recent ones too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.