|
|
|
การเก็บข้อมูลไปเรื่อยๆลง array 2 มิติ โดยส่งค่าไปเป็นการวนลูป |
|
|
|
|
|
|
|
คือ ต้องการให้ array เก็บค่าเป็น array ชุดเดียวถึงแม้ว่าจะส่งค่าไปแบบวนลูปก็ตาม ผลลัพธ์ที่ต้องการดังโค้ดด้านล่าง ไม่ทราบว่าต้องปรับโค้ดอย่างไรบ้างค่ะ
Code (PHP)
<?
function add_arr($n,$id_p,$wait_p,$time,$ES,$EF) {
$data[100][9]= array($n,$id_p,$wait_p,$time,$ES,$EF);
print_r($data);
}
$n = 1;
while($search_rows){
add_arr($n,$id_p,$wait_p,$time,$ES,$EF);
$n++;
}
?>
ผลลัพธ์ที่ได้
Array ( [100] => Array ( [9] => Array ( [0] => 1 [1] => 1 [2] => - [3] => 5 [4] => 0 [5] => 5 ) ) )
Array ( [100] => Array ( [9] => Array ( [0] => 2 [1] => 2 [2] => - [3] => 4 [4] => 0 [5] => 4 ) ) )
Array ( [100] => Array ( [9] => Array ( [0] => 3 [1] => 3 [2] => - [3] => 8 [4] => 0 [5] => 8 ) ) )
Array ( [100] => Array ( [9] => Array ( [0] => 4 [1] => 4 [2] => 1 [3] => 6 [4] => 5 [5] => 11 ) ) )
Array ( [100] => Array ( [9] => Array ( [0] => 5 [1] => 5 [2] => 1 [3] => 4 [4] => 5 [5] => 9 ) ) )
Array ( [100] => Array ( [9] => Array ( [0] => 6 [1] => 6 [2] => 1,2 [3] => 7 [4] => 5 [5] => 12 ) ) )
Array ( [100] => Array ( [9] => Array ( [0] => 7 [1] => 7 [2] => 3 [3] => 1 [4] => 8 [5] => 9 ) ) )
Array ( [100] => Array ( [9] => Array ( [0] => 8 [1] => 8 [2] => 7 [3] => 3 [4] => 9 [5] => 12 ) ) )
Array ( [100] => Array ( [9] => Array ( [0] => 9 [1] => 9 [2] => 1,4,5 [3] => 3 [4] => 11 [5] => 14 ) ) )
ผลลัพธ์ที่ต้องการ <----------------------------------------------
Array ( [100][9] => Array ( [0][0] => 1 [0][1] => 1 [0][2] => - [0][3] => 5 [0][4] => 0 [0][5] => 5
[1][0] => 2 [1][1] => 2 [1][2] => - [1][3] => 4 [1][4] => 0 [1][5] => 4
[2][0] => 3 [2][1] => 3 [2][2] => - [2][3] => 8 [2][4] => 0 [2][5] => 8
[3][0] => 4 [3][1] => 4[3] [2] => 1 [3][3] => 6 [3][4] => 5 [3][5] => 11
[4][0] => 5 [4][1] => 5 [4][2] => 1 [4][3] => 4 [4][4] => 5 [4][5] => 9
[5][0] => 6 [5][1] => 6 [5][2] => 1,2 [5][3] => 7 [5][4] => 5[5] [5] => 12
[6][0] => 7 [6][1] => 7 [6][2] => 3 [6][3] => 1 [6][4] => 8 [6][5] => 9
[7][0] => 8 [7][1] => 8 [7][2] => 7 [7][3] => 3 [7][4] => 9 [7][5] => 12
[8][0] => 9 [8][1] => 9 [8][2] => 1,4,5 [8][3] => 3 [8][4] => 11 [8][5] => 14 ))
Tag : PHP
|
|
|
|
|
|
Date :
2011-03-17 22:07:44 |
By :
kalakate |
View :
2456 |
Reply :
0 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|