Get the final value of a multidimensional array

I have a multidimensional array of undefined length that looks like

Array ( [0] => Array ( [price] => 75 ) [1] => Array ( [price] => 90 ) [2] => Array ( [price] => 95 ) [3] => Array ( [price] => 130 ) ) 

How can I get the price value of the last element in an array?

Greetings

+4
source share
2 answers

Try the following: $array - your input array

 $arr = end($array); echo $arr['price']; 

EDIT: And with PHP 5.4 or later: end($array)['price'] - fab (Comment by fab)

+11
source

just use this code $arr - your array.

 echo $arr[count($arr) - 1]['price']; 
+2
source

All Articles