The for loop only has limited number indexes. After the for and foreach traversal ends, you do not need to perform the reset () operation on the data for the next traversal, And the each method is required.
The for loop only has limited number indexes. After the for and foreach traversal ends, you do not need to perform the reset () operation on the data for the next traversal, And the each method is required.
The Code is as follows:
//
$ Arr = array ('A' => 'abc', 'B' => 123, 'c' => true );
// B
// $ Arr = range ('A', 'D ');
// 1
For ($ I = 0; $ I
Echo $ arr [$ I]. ',';
Echo'
';
// 2
Foreach ($ arr as $ key)
Echo "$ key ,";
Echo'
';
// 3
Foreach ($ arr as $ key => $ val)
Echo "$ key-$ val ,";
Echo'
';
// 4
Reset ($ arr );
While ($ item = each ($ arr )){
Echo $ item ['key']. '-'. $ item ['value']. ',';
}
Echo'
';
// 5
Reset ($ arr );
While (list ($ key, $ val) = each ($ arr )){
Echo "$ key-$ val ,";
}
Echo'
';
?>
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.