0

I tried to get an answer for this in other posts with no luck, hope someone can help me here, i have a multidimensional array:

Array ( 
    [0] => stdClass Object ( 
        [affectsVersions] => Array ( ) 
        [assignee] => hmontes 
        [attachmentNames] => Array ( ) 
        [components] => Array ( ) 
        [created] => 2012-08-15T05:31:26.000Z
        [customFieldValues] => Array ( 
            [0] => stdClass Object ( 
                [customfieldId] => customfield_10201
                [key] => [values] => Array ( 
                    [0] => 123456
                )
            )
            [1] => stdClass Object ( 
                [customfieldId] => customfield_10004
                [key] => [values] => Array ( 
                    [0] => 30
                )
            )
        )
        [description] => [duedate] => [environment] => [fixVersions] => Array ( )
        [id] => 10228
        [key] => NTP-29
        [priority] => 3
        [project] => NTP
        [reporter] => hmontes
        [resolution] => [status] => 1
        [summary] => case 123456
        [type] => 3
        [updated] => 2012-08-15T05:31:26.000Z
        [votes] => 0
    )
)

this is what i get when i do a print_r with the array variable, i need to search and get the value from [key] that would be in this case NTP-29 and keep it in a variable as string.

5
  • What do you mean search and get the value from key? Do you know the key or are you trying to get the key by searching for the value? Commented Aug 18, 2012 at 6:17
  • @sberry you're a gentleman and a scholar. I thank you :) Commented Aug 18, 2012 at 6:22
  • 2
    @JaredDrake yeah, that wasn't fun at all. Commented Aug 18, 2012 at 6:22
  • An up-vote for you, for the correct answer. Commented Aug 18, 2012 at 6:24
  • Similar question with answers Commented Aug 18, 2012 at 6:25

2 Answers 2

3

You can get the value of an array by the key using $array['keyName'];

But, for you it looks like you just need to go deeper $array[0]['key'];

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

1 Comment

It will work. The toplevel array has only a single numerically indexed element.
0

Both arrays values and properties of objects can be accessed using associative array syntax. To get the value of the key property in your object within the array you'd do the following, assuming $array is a variable containing a reference to your array:

$key = $array[0]['key']; // accesses NTP-29 in this case.

Here's another way to access the same property, using object property-access syntax:

$key = $array[0]->key; // also accesses NTP-29.

1 Comment

Thank you all for your help, i was working late last night and didn't format anything in the question, i do appreciate your help, it worked for me like expected!, great work!.

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.