Copy codeThe Code is as follows: <? Php
//
$ Arr = array ('A' => 'abc', 'B' => 123, 'c' => true );
// B
// $ Arr = range ('A', 'D ');
// 1
For ($ I = 0; $ I <sizeof ($ arr); $ I ++)
Echo $ arr [$ I]. ',';
Echo '<br/> ';
// 2
Foreach ($ arr as $ key)
Echo "$ key ,";
Echo '<br/> ';
// 3
Foreach ($ arr as $ key => $ val)
Echo "$ key-$ val ,";
Echo '<br/> ';
// 4
Reset ($ arr );
While ($ item = each ($ arr )){
Echo $ item ['key']. '-'. $ item ['value']. ',';
}
Echo '<br/> ';
// 5
Reset ($ arr );
While (list ($ key, $ val) = each ($ arr )){
Echo "$ key-$ val ,";
}
Echo '<br/> ';
?>
Use the Statement a $ arr = array ('A' => 'abc', 'B' => 123, 'c' => true ); initialize $ arr to obtain the numeric index array. The output is as follows:
,,,
Abc, 123, 1,
A-abc, b-123, C-1,
A-abc, b-123, C-1,
A-abc, b-123, C-1, use the statement B $ arr = range ('A', 'D'); initialize $ arr to get the associated array, the output is as follows:
A, B, c, d,
A, B, c, d,
0-a, 1-b, 2-c, 3-d,
0-a, 1-b, 2-c, 3-d,
0-a, 1-b, 2-c, 3-d, and for loops only limit the number index. After the for and foreach traversal ends, you do not need to reset () The data for next traversal, the each method is required.