prevREWINDS the internal ARRAY pointer.
This function behaves just like next, except it rewinds the internal array pointer one place instead of advancing it.
To test the returned value the operator === must be used.
This function may return also a non-Boolean value which is evaluated as FALSE.
<?php
mix prev ( arr &$array )
where,
$array = The given input ARRAY
?>
$array
The given input array.
Can be passed by reference.
EXERCISE
<?php
$arr01b = [ "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($arr01b);
echo '<br><br>The current INDEX:<br>';
$ndx01b = key($arr01b);
print_r($ndx01b);
echo '<br><br>The current ELEMENT:<br>';
$frs01b = current($arr01b);
print_r($frs01b);
$lst01b = end($arr01b);
echo '<br><br><br>The LAST INDEX:<br>';
$key01b = key($arr01b);
print_r($key01b);
echo '<br><br>The LAST ELEMENT:<br>';
print_r($lst01b);
$prev01b1 = prev($arr01b);
$prev01b2 = prev($arr01b);
echo '<br><br><br>Internal pointer moved back twice.
<br>The current INDEX:<br>';
$key01b2 = key($arr01b);
print_r($key01b2);
echo '<br><br>Internal pointer moved back twice.
<br>The current ELEMENT:<br>';
print_r($prev01b2);
?>
RESULT
The 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 current INDEX:
first index
The current ELEMENT:
FIRST ELEMENT
The LAST INDEX:
sixth index
The LAST ELEMENT:
SIXTH ELEMENT
Internal pointer moved back twice.
The current INDEX:
fourth index
Internal pointer moved back twice.
The current ELEMENT:
FOURTH ELEMENT
EXERCISE
<?php
$arr02b = [];
echo 'The given ARRAY:<br>';
print_r($arr02b);
echo '<br><br>The current INDEX:<br>';
$ndx02b = key($arr02b);
var_dump($ndx02b);
echo '<br><br>The current ELEMENT:<br>';
$frs02b = current($arr02b);
var_dump($frs02b);
$lst02b = end($arr02b);
echo '<br><br><br>The LAST INDEX:<br>';
$key02b = key($arr02b);
var_dump($key02b);
echo '<br><br>The LAST ELEMENT:<br>';
var_dump($lst02b);
$prev02b1 = prev($arr02b);
$prev02b2 = prev($arr02b);
echo '<br><br><br>Internal pointer moved back twice.
<br>The current INDEX:<br>';
$key02b2 = key($arr02b);
var_dump($key02b2);
echo '<br><br>Internal pointer moved back twice.
<br>The current ELEMENT:<br>';
var_dump($prev02b2);
?>
RESULT
The given ARRAY:
Array()
The current INDEX:
NULL
The current ELEMENT:
bool(false)
The LAST INDEX:
NULL
The LAST ELEMENT:
bool(false)
Internal pointer moved back twice.
The current INDEX:
NULL
Internal pointer moved back twice.
The current ELEMENT:
bool(false)