从数组PHP中获取价值

时间:2017-02-01 21:09:10

标签: php arrays multidimensional-array

我有一个名为$ all的变量,当我执行print_r($ all)时,它打印出来:

Array ( [2016] => Array ( [target] => 150 [tv1] => 32 [radio1] => 8 [tv2] => 19 [radio2] => 50 [tv3] => 30 [radio3] => 11 [tv4] => 10 [radio4] => 33 [total_actual] => 193 [variance] => 43 [variance_reason] => Reason one ) [2017] => Array ( [target] => 120 [tv1] => 34 [radio1] => 21 [tv2] => 31 [radio2] => 44 [tv3] => 12 [radio3] => 25 [tv4] => 20 [radio4] => 19 [total_actual] => 206 [variance] => 86 [variance_reason] => ) )

如何只提取20162017(数组的键)?谢谢!

2 个答案:

答案 0 :(得分:1)

print($all['2016']);

print($all['2017']);

答案 1 :(得分:0)

您可以使用array_keys(): -

array_keys($all);

示例: - https://eval.in/728660