Beispiel #1
0
 function _process_centre_service_datas_for_line($datas)
 {
     $centre_array = array();
     $centre_id_name_array = array();
     $first_line_array = array('date');
     $custom_centre_array = array();
     foreach ($datas as $data) {
         if (!in_array($data->centre_id, $centre_array)) {
             $centre_array[] = $data->centre_id;
             $first_line_array[] = $data->centre;
             $custom_centre_array[$data->centre_id] = 0;
         }
     }
     $start_time = $this->input->get('from_date') ? strtotime($this->input->get('from_date')) : strtotime('-1 month');
     $end_time = $this->input->get('to_date') ? strtotime($this->input->get('to_date')) : time();
     $pre_line_chart = array();
     foreach ($datas as $key => $data) {
         if (!isset($pre_line_chart[$data->payment_received_date][$data->centre_id])) {
             $pre_line_chart[$data->payment_received_date][$data->centre_id] = 0;
         }
         $pre_line_chart[$data->payment_received_date][$data->centre_id] += $data->service_amount;
     }
     foreach ($pre_line_chart as $key => &$value) {
         foreach ($centre_array as $k => $v) {
             if (!in_array($v, array_keys($value))) {
                 $value[$v] = 0;
             }
         }
     }
     foreach ($pre_line_chart as $key => &$value) {
         ksort($value);
     }
     if ($this->input->get('interval') == 'monthly') {
         $interval = 2592000;
     } elseif ($this->input->get('interval') == 'weekly') {
         $interval = 604800;
     } else {
         $interval = 86400;
     }
     $interval_start = $start_time;
     $final_pre_line_chart = array();
     for ($i = $start_time + $interval; $i <= $end_time; $i += $interval) {
         $interval_end = $i;
         if ($this->input->get('interval') == 'weekly' or $this->input->get('interval') == 'monthly') {
             $interval_index = date('M j', $interval_start) . '-' . date('M j', $interval_end);
         } else {
             $interval_index = date('M j', $interval_end);
         }
         $final_pre_line_chart[$interval_index] = $custom_centre_array;
         foreach ($pre_line_chart as $index => $val) {
             if (strtotime($index) >= $interval_start and strtotime($index) <= $interval_end) {
                 $final_pre_line_chart[$interval_index] = sum_array($final_pre_line_chart[$interval_index], $val);
             }
         }
         $interval_start = $i;
     }
     if ($interval_start < $end_time) {
         if ($this->input->get('interval') == 'weekly' or $this->input->get('interval') == 'monthly') {
             $interval_index = date('M j', $interval_start) . '-' . date('M j', $end_time);
         } else {
             $interval_index = date('M j', $end_time);
         }
         $final_pre_line_chart[$interval_index] = $custom_centre_array;
         foreach ($pre_line_chart as $index => $val) {
             if (strtotime($index) >= $interval_start and strtotime($index) <= $end_time) {
                 $final_pre_line_chart[$interval_index] = sum_array($final_pre_line_chart[$interval_index], $val);
             }
         }
     }
     $pre_line_chart = $final_pre_line_chart;
     $line_chart = array($first_line_array);
     foreach ($pre_line_chart as $keyz => $valuez) {
         $temp_array = array($keyz);
         foreach ($valuez as $k => $v) {
             $temp_array[] = $v;
         }
         $line_chart[] = $temp_array;
     }
     return $line_chart;
 }
function average_array($array, $column)
{
    return sum_array($array, $column) / count($array);
}
<?php

include_once "functions.php";
$arNumb = range(1, 10);
$arNumb1 = array_merge(array(16), range(2, 10));
$sum = sum($arNumb);
// print_array();
// print_array($arNumb);
// print_array($sum);
$num1 = 2;
$num2 = 2;
$result = 0;
//echo sum_ab($num1,$num2);
/*$res = mul($num1,$num2,$result);
echo $result,"<br>";
echo $res;*/
print_array(my_pow($arNumb1));
print_array(sum_array($arNumb, $arNumb1));
print_array(sum_array(my_pow($arNumb), my_pow($arNumb1)));
<?php

$requestVar = array('inputPath', 'outputPath', 'action');
foreach ($requestVar as $val) {
    ${$val} = isset($_REQUEST[$val]) ? $_REQUEST[$val] : '';
}
if ($inputPath) {
    $inputVal = get_input_values($inputPath);
}
if (!$action || !$inputPath || !$inputVal) {
    goto html;
}
switch ($action) {
    case "sum":
        $outputVal = sum_array($inputVal);
        break;
    case "product":
        $outputVal = product_array($inputVal);
        break;
    case "miscellany":
        $outputVal = miscellany_array($inputVal);
        break;
    default:
        break;
}
if ($outputVal) {
    $dir = $outputPath ? $outputPath : ".";
    save_output($outputVal, "{$dir}/output_{$action}.txt");
}
// FUNCTIONS
function get_input_values($inputPath)