Q:

Write a PHP script to get the last value of an array without affecting the pointer

0

Write a PHP script to get the last value of an array without affecting the pointer

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

<?php
$colors = array('c1' => 'Red',  'c2' => 'Green',  'c3' => 'White',  'c4' => 'Black'); 
echo next($colors)."\n";  
$last = array_pop(array_keys(array_flip($colors)));
echo $last."\n";   
echo current($colors)."\n";  
?>

Sample Output:

Green                                                       
Black                                                       
Green

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now