-1

I need to get a value from an array the array is made like this

$resultOfAdd[“CaseAndMatterResult”][“ResultInfo”][“ReturnCode”];

and it gives an output of this

Array (
    [AddCaseAndMatterResult] => Array (
        [ResultInfo] => Array (
            [ReturnCode] => OK
            [Errors] =>
            [Warnings] =>
        )
        [CaseID] => 4880062
        [MatterID] => 4950481
        [LeadID] => 0
        [CustomerID] => 0
    )
)

All I want to do is put the part "MatterID" into a variable. how would I achieve this.

I have tried

$matterID = array($resultOfAdd["MatterID"]);

and this does not work.

2
  • 1
    The string "does not work" is not a built-in error message in PHP. Commented Jul 3, 2012 at 10:04
  • True, but the question was clear in intent and method. Far better candidates for vote-down, I reckon! Commented Jul 3, 2012 at 12:29

3 Answers 3

1

This is a multi-dimensional, associative array. Think of it like floors of a building. The key MatterID does not live in the first dimension (floor), rather on the second, in the AddCaseAndMatterResult sub-array.

$matterID = $resultOfAdd['AddCaseAndMatterResult']['MatterID']

Successive dimensions of an array are specified with successive square-brackets, each naming the key to look in (this is true of most languages).

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

Comments

1
$matterID = $yourArray['AddCaseAndMatterResult']['MatterID'];

2 Comments

the array is $resultOfAdd not $resultof?
maybe... doesnt matter, the index is AddCase[..].. and not Case[..] so he writes about two diffrent arrays anyway...but it shows how to get it..
0

Use this way:

$matterID = $resultOfAdd['AddCaseAndMatterResult']['MatterID'];

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.