下面是数组$ projectout的var_dump,但是当我尝试print_r($ projectout [0])时,它给出了错误未定义的偏移字符串0。 我怎样才能根据'小时'
对这个数组进行排序array(5) {
["hours"]=>
float(0)
["minutes"]=>
float(0)
["pid"]=>
string(1) "1"
["name"]=>
string(6) "Tuorla"
["uname"]=>
string(15) "Sami Suo-Heikki"
}
array(6) {
["hours"]=>
float(14)
["minutes"]=>
float(0)
["tasks"]=>
array(2) {
[0]=>
array(6) {
["hours"]=>
float(11)
["minutes"]=>
float(0)
["reports"]=>
array(6) {
[0]=>
array(4) {
["id"]=>
string(2) "84"
["details"]=>
string(18) "General management"
["hours"]=>
float(2)
["minutes"]=>
float(0)
}
[1]=>
array(4) {
["id"]=>
string(2) "85"
["details"]=>
string(18) "General management"
["hours"]=>
float(2)
["minutes"]=>
float(0)
}
[2]=>
array(4) {
["id"]=>
string(2) "86"
["details"]=>
string(18) "General management"
["hours"]=>
float(2)
["minutes"]=>
float(0)
}
[3]=>
array(4) {
["id"]=>
string(2) "87"
["details"]=>
string(18) "General management"
["hours"]=>
float(2)
["minutes"]=>
float(0)
}
[4]=>
array(4) {
["id"]=>
string(2) "88"
["details"]=>
string(18) "General management"
["hours"]=>
float(1)
["minutes"]=>
float(0)
}
[5]=>
array(4) {
["id"]=>
string(2) "99"
["details"]=>
string(35) "Associating with Turun talouskeskus"
["hours"]=>
float(2)
["minutes"]=>
float(0)
}
}
["tid"]=>
string(2) "29"
["name"]=>
string(10) "Organising"
["category"]=>
string(10) "Organising"
}
[1]=>
array(6) {
["hours"]=>
float(3)
["minutes"]=>
float(0)
["reports"]=>
array(1) {
[0]=>
array(4) {
["id"]=>
string(2) "89"
["details"]=>
string(34) "Planning the design for cloudit.fi"
["hours"]=>
float(3)
["minutes"]=>
float(0)
}
}
["tid"]=>
string(2) "30"
["name"]=>
string(6) "Design"
["category"]=>
string(6) "Design"
}
}
["pid"]=>
string(1) "2"
["name"]=>
string(14) "Jalkapallopeli"
["uname"]=>
string(15) "Sami Suo-Heikki"
}
array(5) {
["hours"]=>
float(0)
["minutes"]=>
float(0)
["pid"]=>
string(1) "3"
["name"]=>
string(4) "TScP"
["uname"]=>
string(15) "Sami Suo-Heikki"
}
array(5) {
["hours"]=>
float(0)
["minutes"]=>
float(0)
["pid"]=>
string(1) "4"
["name"]=>
string(5) "Sitra"
["uname"]=>
string(15) "Sami Suo-Heikki"
}
array(5) {
["hours"]=>
float(0)
["minutes"]=>
float(0)
["pid"]=>
string(1) "5"
["name"]=>
string(12) "Laserkeilaus"
["uname"]=>
string(15) "Sami Suo-Heikki"
}
array(6) {
["hours"]=>
float(36)
["minutes"]=>
float(33)
["tasks"]=>
array(2) {
[0]=>
array(6) {
["hours"]=>
float(30)
["minutes"]=>
float(33)
["reports"]=>
array(2) {
[0]=>
array(4) {
["id"]=>
string(2) "69"
["details"]=>
string(15) "Adding all divs"
["hours"]=>
float(23)
["minutes"]=>
float(33)
}
[1]=>
array(4) {
["id"]=>
string(2) "73"
["details"]=>
string(5) "gsdgs"
["hours"]=>
float(7)
["minutes"]=>
float(0)
}
}
["tid"]=>
string(2) "24"
["name"]=>
string(4) "HTML"
["category"]=>
string(15) "Web development"
}
[1]=>
array(6) {
["hours"]=>
float(6)
["minutes"]=>
float(0)
["reports"]=>
array(1) {
[0]=>
array(4) {
["id"]=>
string(2) "71"
["details"]=>
string(12) "Making stuff"
["hours"]=>
float(6)
["minutes"]=>
float(0)
}
}
["tid"]=>
string(2) "25"
["name"]=>
string(3) "CSS"
["category"]=>
string(15) "Web Development"
}
}
["pid"]=>
string(1) "6"
["name"]=>
string(16) "Opetusmateriaali"
["uname"]=>
string(15) "Sami Suo-Heikki"
}
array(5) {
["hours"]=>
float(0)
["minutes"]=>
float(0)
["pid"]=>
string(1) "7"
["name"]=>
string(15) "3D-projekti NDA"
["uname"]=>
string(15) "Sami Suo-Heikki"
}
array(6) {
["hours"]=>
float(31)
["minutes"]=>
float(0)
["tasks"]=>
array(2) {
[0]=>
array(6) {
["hours"]=>
float(12)
["minutes"]=>
float(0)
["reports"]=>
array(2) {
[0]=>
array(4) {
["id"]=>
string(2) "77"
["details"]=>
string(17) "Making preparings"
["hours"]=>
float(6)
["minutes"]=>
float(0)
}
[1]=>
array(4) {
["id"]=>
string(2) "83"
["details"]=>
string(76) "I counted the total amount of time that I spent while contacting the client."
["hours"]=>
float(6)
["minutes"]=>
float(0)
}
}
["tid"]=>
string(2) "27"
["name"]=>
string(10) "Contacting"
["category"]=>
string(26) "Client affair and planning"
}
[1]=>
array(6) {
["hours"]=>
float(19)
["minutes"]=>
float(0)
["reports"]=>
array(5) {
[0]=>
array(4) {
["id"]=>
string(2) "78"
["details"]=>
string(39) "New header and other graphical changes."
["hours"]=>
float(3)
["minutes"]=>
float(0)
}
[1]=>
array(4) {
["id"]=>
string(2) "79"
["details"]=>
string(51) "New search engine http://docpoint.info/etsielokuvaa"
["hours"]=>
float(4)
["minutes"]=>
float(0)
}
[2]=>
array(4) {
["id"]=>
string(2) "80"
["details"]=>
string(51) "New search engine http://docpoint.info/etsielokuvaa"
["hours"]=>
float(4)
["minutes"]=>
float(0)
}
[3]=>
array(4) {
["id"]=>
string(2) "81"
["details"]=>
string(51) "New search engine http://docpoint.info/etsielokuvaa"
["hours"]=>
float(4)
["minutes"]=>
float(0)
}
[4]=>
array(4) {
["id"]=>
string(2) "82"
["details"]=>
string(51) "New search engine http://docpoint.info/etsielokuvaa"
["hours"]=>
float(4)
["minutes"]=>
float(0)
}
}
["tid"]=>
string(2) "28"
["name"]=>
string(6) "Coding"
["category"]=>
string(9) "Technical"
}
}
["pid"]=>
string(1) "9"
["name"]=>
string(17) "Kehitysehdotukset"
["uname"]=>
string(15) "Sami Suo-Heikki"
}
array(5) {
["hours"]=>
float(0)
["minutes"]=>
float(0)
["pid"]=>
string(2) "10"
["name"]=>
string(11) "Tic-tac-toe"
["uname"]=>
string(15) "Sami Suo-Heikki"
}
array(5) {
["hours"]=>
float(0)
["minutes"]=>
float(0)
["pid"]=>
string(2) "17"
["name"]=>
string(11) "IndustrySim"
["uname"]=>
string(15) "Sami Suo-Heikki"
}
这让我坚持了3个小时。多克斯寻求帮助。 以下是完整的代码
public static function getReports($project,$start,$end,$uid=Null){
$projectOut = array();
$username=null;
$user = Users::model()->findByPk($uid);
if (!empty($user)){
$username= $user->name;
}
$tasks = Task::getProjectTasks($project->pid);
$projectOut['hours'] = 0;
$projectOut['minutes']= 0;
foreach($tasks->getData() as $task) {
if(Task::isUserinTask($task->tid,$uid) || $uid == null){
$taskOut = array();
$reports = Reports::getTaskReports($task->tid,$start,$end,$uid);
$taskOut['hours'] = 0;
$taskOut['minutes'] = 0;
foreach($reports->getData() as $report){
$reportOut = array();
$reportOut['id']=$report->rid;
$reportOut['details']=$report->details;
$reportTime = (strtotime($report->end)-strtotime($report->start))/3600;
$reportOut['hours'] = floor($reportTime);
$reportOut['minutes'] = round(($reportTime - $reportOut['hours'])*60);
$taskOut['reports'][]=$reportOut;
$taskOut['hours'] += $reportOut['hours'];
$taskOut['minutes'] += $reportOut['minutes'];
}
$taskOut['tid']=$task->tid;
$taskOut['name']=$task->name;
$taskOut['category']=$task->category;
$taskM = $taskOut['hours']*60 + $taskOut['minutes'];
$taskOut['hours'] = floor($taskM/60);
$taskOut['minutes'] = round(($taskM/60 - $taskOut['hours'])*60);
$projectOut['tasks'][]=$taskOut;
$projectOut['hours'] += $taskOut['hours'];
$projectOut['minutes'] += $taskOut['minutes'];
}
}
$projectM = $projectOut['hours']*60 + $projectOut['minutes'];
$projectOut['hours'] = floor($projectM/60);
$projectOut['minutes'] = round(($projectM/60 - $projectOut['hours'])*60);
$projectOut['pid']=$project->pid;
$projectOut['name']=$project->name;
$projectOut['uname']=$username;
var_dump($projectOut);