CopyPastehas never been so tasty!

Reset array pointer in PHP

by anonymous

  • 0
  • 0
  • 0
78 views

http://codingvilla.com/reset-array-pointer-php-single-article-664.aspx

In this simple article you will learn that how we can reset array pointer in PHP.


Arrays:

Arrays are just like the variable that store values but arrays can be used to store more than one value. Variable only store one value. There are three types of arrays

· Numeric arrays
· Associative array
· Multidimensional array

Pointers:

Pointers are used to point specific location. These are just like indexes that show the position of a variable.

Reset () function:

It is used to reset the pointer of an array. Reset () function basically reset the pointer to the first element of an array

Syntax:

Reset(array)

Reset array pointer using reset() function in PHP:

To reset the pointer of an array we use the reset () function in php. It is the built-in function that set the pointer to the first element of an array. This function takes array as a parameter whose pointer we want to reset. In the given code we reset the array spice by using the reset () function and it returns the first element on the succeess or false on fail.

Code:


<?php
$spices = array("A", "B", "C", "D", "E");
reset($spices);
$a_spice = each($spices);
print_r($a_spice[1]);
echo "<br>";
print_r($a_spice["value"]);
?>


Above is simple code to reset the array using reset () function in php.

This simple article tells that how we can reset the array using reset () function in php.

Add A Comment: