0%

PHP Laravel 系列 - (3) 資料結構,資料量一多,正規的儲存方式

1. 陣列

1
2
3
4
5
6
7
8
$people = ['john','may','tim'];
/*
Array
(
[name] => john
[age] => 55
)
*/

2. 字典式陣列

1
2
3
4
5
6
7
8
$student = ['name'=>'john','age'=> 55];
/*
Array
(
[name] => john
[age] => 55
)
*/

3. 迴圈操作

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$students = [
['name'=> 'kite' , 'grade'=> 100]
,['name'=> 'snow' , 'grade'=> 85]

];

foreach($students as $key => $student)
{
echo ('第'.$key.'個學生'.$student['name']. "\r\n");
}

/*
第0個學生kite
第1個學生snow
*/