"find the last element of an array while using a foreach loop in php" Code Answer

1

It sounds like you want something like this:

$numItems = count($arr);
$i = 0;
foreach($arr as $key=>$value) {
  if(++$i === $numItems) {
    echo "last index!";
  }
}    

That being said, you don't -have- to iterate over an "array" using foreach in php.

By shwabob on August 31 2022

Answers related to “find the last element of an array while using a foreach loop in php”

Only authorized users can answer the search term. Please sign in first, or register a free account.