php of two ways exemplary array traversal

    When the array traversal php, foreach generally often used to traverse, while traversing rarely used, to make a comparison in the following code.

<?php

$content = ["ID" => 1, "name" => "孙悟空", "company" => "取经公司", "phone" => 13688888888, "email" => "[email protected]"];

// 第一种,while遍历
while( list( $key, $value ) = each( $content ) )
    echo " {$key} => {$value} <br>";

echo '<hr>';

// second, foreach traverse 
the foreach ( $ Content  AS  $ Key => $ value )
     echo "{ $ Key } => { $ value } <br>";

 

Guess you like

Origin www.cnblogs.com/qingsong/p/12024753.html