Problems with the Foreach Loop array
The $account array is as follows
Array
(
[Tencent] = = Array
(
[0] = mylove_fish2008
[1] = Caochengli_love
)
[Sina] = = Array
(
[0] = 2935994540
[1] = 3177446321
)
[163] = = Array
(
[0] = 3395157578
[1] = 8589895537
)
[Sohu] = = Array
(
[0] = 1400582280
[1] = 1044720542
)
)
I'm going to loop this array now, there are two ways
1.foreach ($account as $key = $rows)
{
foreach ($rows as $val)
{
echo $val. ";
}
}
2.foreach ($account [' Tencent '] as $val)
{
echo $val. ";
}
$account [' Sina '], $account [' 163 '], looping like $account [' Sohu ']
Loop the two-dimensional array, which is the high efficiency
------Solution--------------------
References:
Reference: Set your two-dimensional array contains n one array, one-dimensional array has m key values,
So complete the traversal example 1 time complexity
For O (n*m)
Example 2
O (m+m+m) (N) = "O (n*m)
Efficiency I think it should be the same.
Two loops
$t 1 = microtime (true);
$data = Array (' tencent ' =
...
Indeed, as the landlord said, the browser under example 2 of the efficiency ratio of 1 faster nearly a time, but I think the landlord gave example 1 test cases
$t 1 = microtime (true);
$data = Array (' tencent ' = = Array (' CADFDG ', ' dfdgg '), ' sina ' = = Array (' 111 ', ' 4654654 '));
Position should be swapped
Here's my test code.
Class Runtime {
Public $StartTime = 0;
Public $StopTime = 0;
Function Get_microtime () {
List ($usec, $sec) = Explode ("', Microtime ());
Return (float) $usec + (float) $sec);
}
Function Start () {
$this->starttime = $this->get_microtime ();
}
Function Stop () {
$this->stoptime = $this->get_microtime ();
}
Function spent () {
return round (($this->stoptime-$this->starttime) * 1000, 4);