How can I get the current element number when I\'m traversing a array?
I know about count(), but I was hoping there\'s a built-in function for getting the current field
function Index($index) { $Count = count($YOUR_ARRAY); if ($index <= $Count) { $Keys = array_keys($YOUR_ARRAY); $Value = array_values($YOUR_ARRAY); return $Keys[$index] . ' = ' . $Value[$index]; } else { return "Out of the ring"; } } echo 'Index : ' . Index(0);
Replace the ( $YOUR_ARRAY )