我试图在没有运气的其他帖子中得到答案,希望有人可以帮助我,我有一个多维数组:
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
)
)
这是我在使用数组变量执行print_r时得到的结果,我需要搜索并获取[key]中的值,在这种情况下是NTP-29并将其作为字符串保存在变量中。
答案 0 :(得分:3)
您可以使用$ array ['keyName'];
通过键获取数组的值但是,对你来说,看起来你只需要更深入$ array [0] ['key'];
答案 1 :(得分:0)
可以使用关联数组语法访问对象的数组值和属性。要在数组中获取对象中key
属性的值,请执行以下操作,假设$array
是包含对数组的引用的变量:
$key = $array[0]['key']; // accesses NTP-29 in this case.
以下是使用object property-access语法访问同一属性的另一种方法:
$key = $array[0]->key; // also accesses NTP-29.