end


php128 apg

SETS the internal pointer of an ARRAY to its last element.





This function advances the internal pointer of the $array to the last element, and returns its value.

This function returns FALSE if $array is EMPTY.

$array is passed by reference because it is modified by the function.



<?php 

mix end 
arr &$array )


where,

$array The given input ARRAY

?>

 $array 


The given input array.

Can be passed by reference.



  1 EXERCISE   

<?php 

$arr01a 

"continents" => ["América do Sul""Europa"],
     
"countries" => ["Brasil""Chile""Portugal""España"] ];

echo 
'The given ARRAY:<br>';
print_r($arr01a); 

echo 
'<br><br>The last ELEMENT:<br>'
$lst01a end($arr01a); 
print_r($lst01a);
 
echo 
'<br><br>The last INDEX:<br>'
$key01a key($arr01a); 
print_r($key01a); 

?>

 RESULT   

The given ARRAY:
Array ( [continents] => Array ( [0] => América do Sul [1] => Europa ) [countries] => Array ( [0] => Brasil [1] => Chile [2] => Portugal [3] => España ) )

The last ELEMENT:
Array ( [0] => Brasil [1] => Chile [2] => Portugal [3] => España )

The last INDEX:
countries


  2 EXERCISE   

<?php

$arr02b 
=  [ "first index" => "FIRST ELEMENT",
               
"second index" => "SECOND ELEMENT"
                  
"third index" => "THIRD ELEMENT"
                
"fourth index" => "FOURTH ELEMENT"
                  
"fifth index" => "FIFITH ELEMENT"
                 
"sixth index" => "SIXTH ELEMENT" ];
                 
echo 
'The given ARRAY:<br>'
print_r($arr02b);


echo 
'<br><br>The current INDEX:<br>';
$ndx02b key($arr02b);
print_r($ndx02b);

echo 
'<br><br>The current ELEMENT:<br>';
$frs02b current($arr02b);
print_r($frs02b);

echo 
'<br><br>';

$lst02b end($arr02b);

echo 
'<br><br>The LAST INDEX:<br>';
$key02b key($arr02b);
print_r($key02b);

echo 
'<br><br>The LAST ELEMENT:<br>';
print_r($lst02b);

?>

 RESULT   

he given ARRAY:
Array
(
[first index] => FIRST ELEMENT
[second index] => SECOND ELEMENT
[third index] => THIRD ELEMENT
[fourth index] => FOURTH ELEMENT
[fifth index] => FIFITH ELEMENT
[sixth index] => SIXTH ELEMENT
)

The initial current INDEX:
first index

The initial current ELEMENT:
FIRST ELEMENT



The LAST INDEX:
sixth index

The LAST ELEMENT:
SIXTH ELEMENT