PHP: How to print associative array using while loop?

try this syntax and this is best efficient way to do your job...........

while (list($key, $value) = each($array_expression)) {
       statement
}

<?php


$data = array('a' => 1, 'b' => 2, 'c' => 3);

print_r($data);

while (list($key, $value) = each($data)) {
       echo '$'.$key .'='.$value;
}

?>

For reference please check this link.........

Small Example link here...


The best and easiest way to loop through an array is using foreach

 foreach ($assocArray as $key => $value)
        echo $key . ' = ' . $value . '<br />';

Tags:

Php

Arrays