标签: php arrays multidimensional-array
例如,我有一个数组:
$result = array( array ( 'post_id'=>$post_id, 'user_id'=>90, ), array ( 'post_id'=>$post_id, 'user_id'=>80, ), ..... }
我想得到最后一个$ result元素的键值 - (例如user_id = 10)10。是否有可能实现它?
答案 0 :(得分:2)
您可以将end用于此
end
$end = end($result); print $end['post_id'];//etc.
这也将重置数组的内部指针,因此如果您使用current,next或之后的任何类似内容,则首先需要reset。
current
next
reset
答案 1 :(得分:0)
将end()用于此
end()
$last_id=end($result)['used_id'];
但是,如果您正在使用数组指针执行任何操作,则需要reset(),或使用$last_id=end(array_values($result))
reset()
$last_id=end(array_values($result))