Php 获取具有以特殊字符开头的键的关联数组
我有如下数组Php 获取具有以特殊字符开头的键的关联数组,php,arrays,object,Php,Arrays,Object,我有如下数组 Array ( [0] => stdClass Object ( [id] => 67 [contact_id] => [status] => Complete [is_test_data] => 0 [datesubmitted] => 2018-05-24 03:56:35
Array
(
[0] => stdClass Object
(
[id] => 67
[contact_id] =>
[status] => Complete
[is_test_data] => 0
[datesubmitted] => 2018-05-24 03:56:35
[SessionID] => 1527148487_5b066fc7bdcd75.00827785
[Language] => English
[datestarted] => 2018-05-24 03:54:47
[iLinkID] => 6528804
[sResponseComment] =>
[responseID] => 67
[[question(9)]] => Yes
[[question(24)]] => Satisfied
[[question(25)]] =>
[[question(26)]] =>
[[question(27)]] =>
[[question(28)]] =>
[[question(29)]] =>
[[question(31)]] => Likely
[[question(32)]] =>
[[question(33)]] => 26-35
[[question(35)]] => Male
[[question(36)]] =>
[[question(37)]] => No
)
)
Array
(
[0] => Array
(
[id] => 67
[submitted] => 2018-05-24 03:56:35,
[question_9]=>yes
)
)
我正试着从下面的例子中推导出来
Array
(
[0] => stdClass Object
(
[id] => 67
[contact_id] =>
[status] => Complete
[is_test_data] => 0
[datesubmitted] => 2018-05-24 03:56:35
[SessionID] => 1527148487_5b066fc7bdcd75.00827785
[Language] => English
[datestarted] => 2018-05-24 03:54:47
[iLinkID] => 6528804
[sResponseComment] =>
[responseID] => 67
[[question(9)]] => Yes
[[question(24)]] => Satisfied
[[question(25)]] =>
[[question(26)]] =>
[[question(27)]] =>
[[question(28)]] =>
[[question(29)]] =>
[[question(31)]] => Likely
[[question(32)]] =>
[[question(33)]] => 26-35
[[question(35)]] => Male
[[question(36)]] =>
[[question(37)]] => No
)
)
Array
(
[0] => Array
(
[id] => 67
[submitted] => 2018-05-24 03:56:35,
[question_9]=>yes
)
)
我只是尝试了数组映射
$derived=array_map(function ($a){ return array('id'=>$a->id,
'submitted'=>$a->datesubmitted,
'question_9'=>$a->[question(9)]//this is not a right way, what is best practice
);
}, $survey_array);
error :Parse error: syntax error, unexpected '[', expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$' in
访问对象属性时,可以使用大括号包装特殊字符:
$a->{'[question(9)]'}
注意:这不是关联数组。从您的初始输出来看,$a是一个stdClass对象。的可能重复项