|
|
|
สอบถามเรื่องการรันตัวเลขแบบระบบเลขทะเบียนรหัสนักศึกษาเป็น PHP |
|
|
|
|
|
|
|
<?php
function array_group_by($arr, $key_selector) {
$result = array();
foreach($arr as $i){
$key = $key_selector($i);
$group;
if(!array_key_exists($key, $result)) {
$result[$key] = array();
}
$result[$key][] = $i;
}
return $result;
}
$data = array(
array(1, "Andy", "PHP"),
array(1, "Andy", "C#"),
array(2, "Josh", "C#"),
array(2, "Josh", "ASP"),
array(1, "Andy", "SQL"),
array(3, "Steve", "SQL"),
);
$grouped = array_group_by($data, function($i){ return $i[0]; });
var_dump($grouped);
?>
ผล And voila you get
array(3) {
[1]=>
array(3) {
[0]=>
array(3) {
[0]=>
int(1)
[1]=>
string(4) "Andy"
[2]=>
string(3) "PHP"
}
[1]=>
array(3) {
[0]=>
int(1)
[1]=>
string(4) "Andy"
[2]=>
string(2) "C#"
}
[2]=>
array(3) {
[0]=>
int(1)
[1]=>
string(4) "Andy"
[2]=>
string(3) "SQL"
}
}
[2]=>
array(2) {
[0]=>
array(3) {
[0]=>
int(2)
[1]=>
string(4) "Josh"
[2]=>
string(2) "C#"
}
[1]=>
array(3) {
[0]=>
int(2)
[1]=>
string(4) "Josh"
[2]=>
string(3) "ASP"
}
}
[3]=>
array(1) {
[0]=>
array(3) {
[0]=>
int(3)
[1]=>
string(5) "Steve"
[2]=>
string(3) "SQL"
}
}
}
|
|
|
|
|
Date :
2013-06-28 10:35:36 |
By :
next |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ถ้าจำไม่ผิดรหัสนักศึกษามี 9 ตัว
2 ตัวแรก ปี
สาขาวิชา
ลำดับ ประมาณนี้
ใช้คำสั่ง left rigth http://www.siamfocus.com/1/123.htm
https://www.thaicreate.com/tutorial/mysql-mid-left-right-substring-substr.html
|
|
|
|
|
Date :
2013-06-28 10:41:26 |
By :
compiak |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|