PHP 8.5.0 Beta 2 available for testing

Voting

: four minus three?
(Example: nine)

The Note You're Voting On

jorge at REMOVETHIS-2upmedia dot com
13 years ago
If all you want is the last item of the array without affecting the internal array pointer just do the following:

<?php

function endc( $array ) { return end( $array ); }

$items = array( 'one', 'two', 'three' );
$lastItem = endc( $items ); // three
$current = current( $items ); // one
?>

This works because the parameter to the function is being sent as a copy, not as a reference to the original variable.

<< Back to user notes page

To Top