1 개요[ | ]
- PHP 함수 distinct()
PHP
Copy
function distinct($rows, $column_name) {
$column_values = array();
foreach($rows as $row) {
$column_values[$row[$column_name]] = 1;
}
return array_keys($column_values);
}
2 사용 예시[ | ]
PHP
Copy
$rows = array(
array('id'=>1, 'name'=>'한놈', 'department_id'=>1, 'birth_date'=>'1999-01-01'),
array('id'=>2, 'name'=>'두시기', 'department_id'=>2, 'birth_date'=>'2000-01-01'),
array('id'=>3, 'name'=>'석삼', 'department_id'=>2, 'birth_date'=>'1999-01-01'),
array('id'=>4, 'name'=>'너구리', 'department_id'=>3, 'birth_date'=>'2000-01-01'),
);
print_r( distinct($rows, 'department_id') );
# Array
# (
# [0] => 1
# [1] => 2
# [2] => 3
# )
print_r( distinct($rows, 'birth_date') );
# Array
# (
# [0] => 1999-01-01
# [1] => 2000-01-01
# )
3 같이 보기[ | ]
편집자 Jmnote Jmnote bot
로그인하시면 댓글을 쓸 수 있습니다.