I have a PHP array that has both a varying number of elements and varying types of associations, like so:
$example =
Array
(
[0] => 12345
[1] => 100
[2] => Some String
...
[17] => 2
[18] => 0
[type] => Some String
[inst] => Array
(
[0] => Some String
)
[method] => Some String
)
$other =
Array
(
[0] => 45678
[1] => 250
[2] => Some String
...
[8] => 7
[9] => -2
[inst] => Array
(
[0] => Some String
[1] => Some String
)
)
What I'm trying to do is get the last numerical index in these arrays and some before it. Like, in the first example, I want to get $example[18]
and in the second I want to return $other[9]
.
I was using count($array)-1
before the named associations came into play.