HomeMenu
Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

prev

Description

The prev of Array for PHP rewinds the internal array pointer.

Syntax

prev(
    array|object &$array
): mixed

Parameters

array

The input array.

Return

Returns the array value in the previous place that's pointed to by the internal array pointer, or false if there are no more elements.

Examples

1 · prev

<?

$array =
[
    0,
    1,
    2
];

end($array);

$return = prev($array);

var_export($return);
1

2 · multiple

<?

$array =
[
    0,
    1,
    2,
    3,
    4
];

end($array);

foreach($array as $value)
{
    echo prev($array) . PHP_EOL;
}
3
2
1
0

3 · beyond

<?

$array =
[
    0,
    1,
    2
];

reset($array);

$return = prev($array);

var_export($return);
false

4 · empty

<?

$array = [];

$return = prev($array);

var_export($return);
false