Return the total number of items in an array

Posted 2 years ago

// Takes an array and returns the final key (being the last element)
function endKey($array){
  return key($array);

The above snippet will take an array and return last items key, so if we have an array with 3 items in it. We’d be returned “2”

0 for the first item
1 for the second
2 for the last item in the array