Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
当声明类似时,PHP返回一个对象和一个数组_Php_Arrays_Output - Fatal编程技术网

当声明类似时,PHP返回一个对象和一个数组

当声明类似时,PHP返回一个对象和一个数组,php,arrays,output,Php,Arrays,Output,我在返回多维数组时遇到问题。出于某种原因,当初始化相当相同时,其中两个将作为对象而不是数组返回 我正在创建一张考勤卡,并希望返回过去12个月内员工一个月内迟到和准时的时间百分比 代码: $eID = $_GET['showLatencyValues']; //get the last 12 months $month = time(); for ($i = 1; $i <= 12; $i++) { $month = strtotime( date( 'Y-m-01' )." -$i

我在返回多维数组时遇到问题。出于某种原因,当初始化相当相同时,其中两个将作为对象而不是数组返回

我正在创建一张考勤卡,并希望返回过去12个月内员工一个月内迟到和准时的时间百分比

代码:

$eID = $_GET['showLatencyValues'];

//get the last 12 months
$month = time();
for ($i = 1; $i <= 12; $i++) {
  $month = strtotime( date( 'Y-m-01' )." -$i months");
  $months[] = date("r", $month);
}


$ii = 0;    
for($i = 11; $i >= 0; $i--) {
    $m = explode(" ", $months[$i]);
    $result = $m[2].'. '.$m[3];
    $last12months[$ii][0] = $ii;
    $last12months[$ii][1] = $result;
    $ii++;
}

//set the correct dates
$f = explode(" ", $last12months[0][1]);
$t = explode(" ", $last12months[11][1]);

$from   = $f[1].'-'.letterToNumeric($f[0]).'-01';
$days   = cal_days_in_month(CAL_GREGORIAN, letterToNumeric($t[0]), $t[1]); // 31
$to     = $t[1].'-'.letterToNumeric($t[0]).'-'.$days;

//get the information from database
$sql = mysqli_query($conn, "SELECT DISTINCT `timeIn`,`date` FROM `clock` WHERE `eID`='$eID' AND date BETWEEN '$from' AND '$to'");
$res = mysqli_fetch_array($sql);
$break = explode("-", $res['date']);
$month = $break[1]; //set current month to
$countMonth = 0; //month number
$count = 0; //day number
$sql = mysqli_query($conn, "SELECT min(timeIn) as timeIn,`date` FROM `clock` WHERE `eID`='$eID' AND date BETWEEN '$from' AND '$to' group by date");
while($res = mysqli_fetch_array($sql)) {
    $break = explode("-", $res['date']); //get the current selected month
    if($month != $break[1]) {           //check if current month is the same as selected by database if not then
        $countMonth++; //add current month number
        $count = 0;    //set current day number to 0
        $month = $break[1]; //set the current month to whatever is selected by database
    }
    $timeInData[$countMonth][$count] = $res['timeIn'];
    $count++;
}

$count = 0;
for($i = 0; $i < count($timeInData); $i++) {
    for($s = 0; $s < count($timeInData[$i]); $s++) {
        $firstShift_timeIn = setting($conn, 'timeIn1');
        $secondShift_timeIn = setting($conn, 'timeIn2');
        $lateConsideredAfter = setting($conn, 'lateAfter');

        $actualTime = date("H:i", strtotime($timeInData[$i][$s]));
        if($res_shift['shift'] == 1)    $considerLateTime = date("H:i", strtotime($firstShift_timeIn." +".$lateConsideredAfter." minutes"));
        else                            $considerLateTime = date("H:i", strtotime($secondShift_timeIn." +".$lateConsideredAfter." minutes"));

        if($actualTime > $considerLateTime) $late[$count]++;
        else $onTime[$count]++;                 
    }
    $count++;
}

if($count != 12) {
    $amt = (12-($count))-1;
    for($w = 0; $w <= $amt; $w++) {
        $onTimeYesData[$w][0] = $w;
        $onTimeYesData[$w][1] = 0;
        $onTimeNoData[$w][0] = $w;
        $onTimeNoData[$w][1] = 0;
    }
}

for($q = ($amt+1); $q <= 11; $q++) {
    $total = $onTime[($q-($amt+1))] + $late[($q-($amt+1))];

    $onTimeYesData[$q][0] = $q;

    $onTimeYesData[$q][1] = round(($onTime[($q-($amt+1))]/$total)*100);

    $onTimeNoData[$q][0] = $q;

    $onTimeNoData[$q][1] = round(($late[($q-($amt+1))]/$total)*100);
}

$response[1] = $last12months;
$response[0] = $onTimeYesData;
$response[2] = $onTimeNoData;

echo json_encode($response[1])."\n\n".json_encode($response[0])."\n\n".json_encode($response[2]);
$eID=$\u GET['showlatencyvalue'];
//过去12个月
$month=时间();
对于($i=1;$i=0;$i--){
$m=爆炸(“,$months[$i]);
$result=$m[2]。$m[3];
$LAST12个月[$ii][0]=$ii;
$LAST12个月[$ii][1]=$result;
$ii++;
}
//设定正确的日期
$f=爆炸(“,$LAST12个月[0][1]);
$t=爆炸(“,$LAST12个月[11][1]);
$from=$f[1].-'.字母数字($f[0]).-01';
$days=cal_days(cal_GREGORIAN,letttonumeric($t[0]),$t[1]);//31
$to=$t[1].-'.字母数字($t[0]).-'.$d;
//从数据库中获取信息
$sql=mysqli_查询($conn,“选择不同的'timeIn','date`FROM'clock',其中'eID`='$eID',日期在'$FROM'和'$to'之间);
$res=mysqli\u fetch\u数组($sql);
$break=explode(“-”,$res['date']);
$month=$break[1]//将当前月份设置为
$countMonth=0//月数
$count=0//日数
$sql=mysqli_query($conn,“选择min(timeIn)作为timeIn,`date`FROM`clock`,其中`eID`='$eID',日期介于'$FROM'和'$to'之间,按日期分组”);
而($res=mysqli\u fetch\u数组($sql)){
$break=explode(“-”,$res['date']);//获取当前所选月份
如果($month!=$break[1]){//检查当前月份是否与数据库选择的月份相同,如果不相同,则
$countMonth++;//添加当前月号
$count=0;//将当前天数设置为0
$month=$break[1];//将当前月份设置为数据库选择的任何月份
}
$timeInData[$countMonth][$count]=$res['timeIn'];
$count++;
}
$count=0;
对于($i=0;$i$considerLateTime)$late[$count]+;
else$onTime[$count]++;
}
$count++;
}
如果($count!=12){
$amt=(12-($count))-1;

对于($w=0;$w)如果您的数组没有从0开始的每个数字索引的值,那么在JSON编码时,它将被视为哈希(或“object”,JS-wise)。在您的情况下,它们似乎缺少0索引的值。提示:在JS和JSON中,数组索引从0开始。或者,您可以使用简单的方法:替换
JSON\u encode($yourThing)
with
json\u编码(数组值($yourThing))
。虽然不太漂亮。同意上面的评论。另一方面,我不知道
$amt
!=12
的条件之外定义在哪里。感谢大家的帮助。我真是太傻了,我没有意识到我没有在!=12之外定义$amt。感谢GetSet修复了它。这是整个问题。我也没有hanks to Jeto学到了一些新东西。如果数组中的每个数字索引都没有从0开始的值,那么它将被视为散列(或“object”,JS-wise)当JSON编码时。在您的情况下,它们似乎缺少0索引的值。提示:在JS和JSON中,数组索引从0开始。或者,您可以使用简单的方法:将
JSON\u encode($yourThing)
替换为
JSON\u encode(array\u values($yourThing))
。虽然不太漂亮。同意上面的评论。另一方面,我不知道
$amt
!=12
的条件之外定义在哪里。感谢大家的帮助。我真是太傻了,我没有意识到我没有在!=12之外定义$amt。感谢GetSet修复了它。这是整个问题。我也没有汉克斯和杰托学到了一些新东西。