1<?php
2
3$source_array = [
4 'key1' => 'value1',
5 'key2' => 'value2',
6 'key3' => 'value3'
7];
8
9echo "Last index: " . array_key_last($source_array);
10
11?>
1$numItems = count($arr);
2$i = 0;
3foreach($arr as $key=>$value) {
4 if(++$i === $numItems) {
5 echo "last index!";
6 }
7}
8