我有一个var_dump($array)
生成
array(7)
{
["*attributes"]=> array(4)
{
["type"]=> string(6) "hidden"
["name"]=> string(3) "hmo"
["class"]=> string(12) "form-control"
["id"]=> string(3) "hmo"
}
["*label"]=> NULL
["*labelAttributes"]=> array(0) { }
["*labelOptions"]=> array(0) { }
["*messages"]=> array(0) { }
["*options"]=> array(1)
{
["disable_inarray_validator"]=> bool(true)
}
["*value"]=> string(243) "{"My-Office":{"Floor":"New - ","Walls":"New - ","Door":"New - ","Switches":"New - ","Table":"New - ","Chair":"New - "},"Other office":{"Floor":"New - ","Walls":"New - ","Door":"New - ","Switches":"New - ","Table":"New - ","Chair":"New - "}}"
}
我正在尝试访问最后一个位置的json字符串(* value)但我无法使用$array['*value']
访问它,因为我什么都没有返回。如果我var_dump($array['*value'])
我得到NULL。有谁知道为什么$array['*value']
没有给我我需要的字符串?
答案 0 :(得分:0)
使用
array_values(array_slice($array, -1))[0];
访问数组$ array的最后一个元素。