reset() function in PHP || PHP Reset Function

reset() function in php

Last Updated by Pooja Chikara

0 2837

PHP reset() function is used to reset the position of array pointer means it set the current pointer of an array to the starting item of the array.

Syntax:

reset($array);

here,

$array is a PHP array.


Example:

<?php
$arr1 = array("apple","orange","banana","fig",);
$last_value=end($arr1); // it will set the array pointer to last item and return the last item of array i.e. fig
$reset_value=reset($arr1); // it will reset the array pointer and return the initial element of array i.e. apple
echo "Reset item of array is $reset_value ";
?>

Output:

Note: You should also read prev(), next(), current() and end() functions.



Best WordPress Hosting


Share:

SSL for business, from $12.88


Leave a Reply


Comments
    Waiting for your comments

Coding Tag WhatsApp Chat
Coding Tag WhatsApp Chat