我如何知道 for 循环的最后一次迭代?

Raf*_*fff 2 php for-loop

我的代码中有一个for循环:

$d = count( $v2['field_titles'] );

for( $i=0; $i < $d; $i++ ) {
  $current = 3 + $i;
  echo 'current is' . $current;
}
Run Code Online (Sandbox Code Playgroud)

如果我不知道 的确切数量,我如何知道最后一次迭代$d

我想做类似的事情:

$d = count( $v2['field_titles'] );

for( $i=0; $i < $d; $i++ ) {
  $current = 3 + $i;

  if( this is the last iteration ) {
   echo 'current is ' . $current; 
   // add sth special to the output
  }
  else {
    echo 'current is ' . $current;
  }
}
Run Code Online (Sandbox Code Playgroud)

nic*_*ael 5

if($i==$d-1){
   //last iteration :)
}
Run Code Online (Sandbox Code Playgroud)