Iterate enumerative and associate array using for loop

Submitted by:Jhon Smith

Date added:16 January, 2011

Category:PHP

Iterate enumerative and associate array using for loop in php.

Tags: enumerative array , associate array , php array

Code Snippet:

$list = array(2 => 'Pritesh' , 3 => 'Sumit', 4 => 'Mehul', 'max' => 'pain');
iterate_array_with_for($list);
function iterate_array_with_for($list)
{
$list_count = count($list);
if ($list_count > 0)
{
reset($list);
for ($i = 0; $i < $list_count; $i++, next($list))
{
$value = current($list);
$key = key($list);
print "key $key and value $value <br />";
}
}
 
 

Comments