2015-01-20 2 views
0
Array (
     [attendance_id] => 18 
     [attendance] => 1 
     [student_id] => 1 
     [date] => 2015-01-19 
     [in_time] => 00:00:00 
     [out_time] => 00:00:00 
     [fee_amount] => 15000) 
Array (
     [attendance_id] => 19 
     [attendance] => 1 
     [student_id] => 2 
     [date] => 2015-01-19 
     [in_time] => 00:00:00 
     [out_time] => 00:00:00 
     [fee_amount] => 2000) 
Array (
     [attendance_id] => 20 
     [attendance] => 0 
     [student_id] => 1 
     [date] => 2014-01-15 
     [in_time] => 00:00:00 
     [out_time] => 00:00:00 
     [fee_amount] => 0 
    ) 

이 배열의 공통 값을 계산하고 싶습니다. 방법을 안내하십시오.배열에서 공통 값을 계산하는 방법

으로 내가이 얻고 싶은 결과 :

date  [2014-01-15 ] => 2 
attendance [1] => 2 

이 하루에 한 학생 세부 사항은 위와 같이 시스템에 입력 할 수있는 작은 기관에 대한 사실입니다. 그래서 나는 얼마나 많은 학생들이 특정 날 수업에 왔으며 얼마나 많은 학생들이 수업에 참석하지 못했는지에 대한 보고서를 작성하고 싶습니다.

답변

0

이 시도 ..

<?php 
$array = array(array('18','2015-01-19','15000'),array('2015-01-19','18','22'),array('20','11','22')); 

$newcountarray = array(); 
foreach ($array as $key=>$value) { 
foreach ($value as $newvalue) { 
    if ($foundKey = array_key_exists($newvalue,$newcountarray)) { 
     $newcountarray[$newvalue] += 1; 
    } 
    else{ 
     $newcountarray[$newvalue] = 1; 
    } 
}} 

print_r($newcountarray); 

?> 

출력

Array ([18] => 2 [2015-01-19] => 2 [15000] => 1 [22] => 2 [20] => 1 [11] => 1) 
+1

나는 이것이 출석과 student_id 모두 1로 가치를 배열에 가지고 있기 때문에 작동하지 않을 것 같아요. 더하기이 배열의 배열입니다 – onegun

+0

@ user3696108 나는 내 대답을 업데이 트했습니다. 확인하고 내게 알려주십시오 –

+0

@onegun 내가 내 대답을 업데이 트했습니다. 확인하고 –

0

예 디나의 하루 2015년 1월 19일에 대한

$array = array(array('18',<==row id no 
     '2015-01-19',<=date 
     '1',<=student id> 
     '2'<=present(1),absent(2))), 

     array(array('19',<==row id no 
     '2015-01-19',<=date 
     '2',<=student id> 
     '1'<=present(1),absent(2))), 

그와 같은 말을하자 내가 모두 2를 원한다. stuudent 그리고 그들 중 1 학생은 존재하고 1은 결석합니다

관련 문제