PHP

 Home  Computers & Internet  Web Programming PHP
What is PHP?
Echo
Comments
Variables
Constants
Data Types
number_format()
Character Strings
Mathematical Operators
Comparison Operators
Logical Operators
Joining Strings
explode()
implode()
strtolower()
strtoupper()
strlen()
ucfirst()
ucwords()
strrev()
str_replace()
str_repeat()
trim()
strip_tags()
addslashes()
stripslashes()
strpos()
strrpos()
nl2br()
isset()
unset()
empty()
POST
GET
If Statements
If Else Statements
Elseif Statements
Switch Statements
For Loops
While Loops
Do While Loops
Foreach Loops
File Create
File Open
File Read
File Write
File Delete
fgets()
file_get_contents()
Date & Time
$_SERVER
Sessions
Cookies
Arrays

ITERATING MANUALLY THROUGH AN ARRAY

Iteration refers to a process of walking or traversing through elements of an array and doing something with the values.

Iteration can be done manually by using a pointer to move through an array from one value to another.

There are a few manual functions you can use for this process. These are:

current($array):

Refers to the value the pointer is currently on. By default, at the beginning, the pointer is on the first value.

next($array):

Moves the pointer to the next value to the right of current value.

previous($array):

Moves the pointer to the previous value ie. to the left of current value.

end($array):

Moves the pointer to the last value of the array.

reset($array):

Moves the pointer to the first value of the array.

Example:

$colors=array('blue', 'red', 'green', 'white', 'purple');

$value=current($colors);
echo $value; // outputs blue

$value=next($colors);
echo $value; // outputs red

$value=previous($colors);
echo $value; // outputs blue

$value=end($colors);
echo $value; // outputs purple

$value=reset($colors);
echo $value; // outputs blue

See also:

What Are Arrays?
How To Create Arrays
How To View Arrays
How To Modify Arrays
Array arsort() Function
Array asort() Function
Array rsort() Function
Array sort() Function
Array ksort() Function
Array krsort() Function
Array Echo
Array list() Function
Array count() & sizeof() Function




Home | Privacy Policy | Terms Of Use | Contact Us | Work At Home | Online Jobs | Smart Info | Online Jobs | Data Entry Jobs | Paid Surveys | Info | Info | Typing Jobs | Article Archive | Forum Posting Jobs