Mam takie pytanie mam tablicę, która zawiera takie dane.
[0] {
[0] -> 1.2
[1] -> 3
[2] -> 1.3
}
[1] {
[0] -> 1
[1] -> 3
[2] -> 1.2
}
I teraz chciałbym przekazać tylko 0 i 1 elementów ale tylko 0 rowe czyli tylko 1.2 i 1
daje kod
for ($i = $daystart;$i <= $dayend;$i += 86400 ) {
$days[$j] = $this->calculateAverage($hourStart,$hourEnd,date("Y-m-d H:i:s",$i),date("Y-m-d H:i:s",$i+86400),$type);
$sumMood += $days[$j][1];
$sumAnxiety += $days[$j][0];
$sumNer += $days[$j][2];
$sumStimu += $days[$j][3];
$this->days[$j] = date("Y-m-d",$i);
$j++;
}
if ($dayInput == "on") {
if ($j == 0) {
return 0;
}
return [round($sumMood / $j,2),round($this->sortMood((($days) )),2)];
}
return $days;
I tutaj jest tow zmiennje.$days i teraz jak przekazuje to do funkcji sortMood((($days) )),2)]; to zwraca mi błąd
private function calculateAverage($hourStart,$hourEnd,$dataStart,$dataEnd,$type,$dayInput = "") {
return [round($sumAnxiety / $second,2),round($sumMood / $second,2),round($sumNer / $second,2),round($sumStimu / $second,2)];
...
...
}
public function sortMood($list) {
$sort = $list;
if (count($sort) % 2 == 1) {
$average = array_sum($sort)/count($sort);
array_push($sort, $average);
}
asort($sort);
$count = count($sort)-1;
$tmp = 0;
$tmp2 = 0;
for ($i=0;$i < count($sort) / 2;$i++) {
$tmp = $sort[$count] - $sort[$i];
$count--;
if ($tmp < 0) {
$tmp = -$tmp;
}
$tmp2 += $tmp;
}
if (count($sort) == 0) {
return 0;
}
return ($tmp2 / count($sort));
}