next


php128 apg

ADVANCE the internal pointer of an ARRAY.





This function behaves like current, with one difference, it advances the internal ARRAY pointer one place forward before returning the element value.

This function returns the next ARRAY value and advances the internal ARRAY pointer by one.

This function returns the ARRAY value in the next place that's pointed to by the internal ARRAY pointer, or FALSE if there are no more elements.

To test the returned value the operator === must be used.



<?php

mix next 
arr &$array )


where,

$array The input ARRAY

?>

 $array 


The given input array.

Can be passed by reference.



  1 EXERCISE   

<?php

$arr01a 
= array("countries" => array("Brasil""Chile"), 
                        
"continent" => "South America"); 

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

echo 
'<br><br>The pointer advances the 1st time.';
echo 
'<br>The current INDEX:<br>';

next($arr01a);

$ndx01ca key($arr01a);

// The current element
$ele01ca current($arr01a);

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

print_r($ele01ca);

?>

 RESULT   

The given ARRAY:
Array ( [countries] => Array ( [0] => Brasil [1] => Chile ) [continent] => South America )

The pointer advances the 1st time.
The current INDEX:
continent

The current ELEMENT:
South America


  2 EXERCISE   

<?php

$arr02a 
= ["countries" => ["Brasil""Chile"], 
                        
"continent" => "South America"]; 
echo 
'The given ARRAY:<br>'
print_r($arr02a);

echo 
'<br><br>The pointer advances the 1st time.';
echo 
'<br>The current INDEX:<br>';
next($arr02a);

$ndx02ca1 key($arr02a);
print_r($ndx02ca1);

echo 
'<br><br>The current ELEMENT:<br>';
$ele02ca1 current($arr02a);
print_r($ele02ca1);

echo 
'<br><br>The pointer advances the 2nd time.';
echo 
'<br>The current INDEX:<br>';
next($arr02a);

$ndx02ca2 key($arr02a);
var_dump($ndx02ca2);

echo 
'<br><br>The current ELEMENT:<br>';
$ele02ca2 current($arr02a);
var_dump($ele02ca2);


?>

 RESULT   

The given ARRAY:
Array ( [countries] => Array ( [0] => Brasil [1] => Chile ) [continent] => South America )

The pointer advances the 1st time.
The current INDEX:
continent

The current ELEMENT:
South America

The pointer advances the 2nd time.
The current INDEX:
NULL

The current ELEMENT:
bool(false)


  3 EXERCISE   

<?php

echo 'The given ARRAY:<br>'
$arr03a = array(=> 1=> 2=> 4);

print_r($arr03a);

echo 
'<br><br>The pointer advances the 1st time.';
echo 
'<br>The current INDEX: ';
next($arr03a);

$ndx03ca1 key($arr03a);
print_r($ndx03ca1);

echo 
'<br><br>The current ELEMENT: ';
$ele03ca1 current($arr03a);
print_r($ele03ca1);

echo 
'<br><br>The pointer advances the 2nd time.';
echo 
'<br>The current INDEX: ';
next($arr03a);

$ndx03ca2 key($arr03a);
print_r($ndx03ca2);

echo 
'<br><br>The current ELEMENT: ';
$ele03ca2 current($arr03a);
print_r($ele03ca2);

?>

 RESULT   

The given ARRAY:
Array ( [1] => 1 [2] => 2 [3] => 4 )

The pointer advances the 1st time.
The current INDEX: 2

The current ELEMENT: 2

The pointer advances the 2nd time.
The current INDEX: 3

The current ELEMENT: 4