<?php /*Simplex internet PH Developer team Project: Count the number of '8' in the range from 1 to 10,000. (ex. 8831 => 2, 8888 => 4) Author: Ramil T. Angeles Date: 11-11-2015 filename: phptest2.php */ function count_num($from, $to) { //create function for counting the numbers. foreach (range($from, $to) as $number) { // loop range fronm 1 to 10000; $arr_num[$number] = substr_count("{$number}", '8'); //created $arr_num array with index value from $number // array value is substr_count(string, 8); } return $arr_num; } $results = count_num(1, 10000); //call function count_num and pass a parameter range 1 to 10000 $total = array_sum($results); echo "Total number of 8 range 1 to 10000 are: " . $total . "<br>";
$data = $table->data($page); foreach ($data as $dd) { $gdata[] = [strtotime($dd['day']) * 1000, (int) $dd['day_num']]; } } $gdata = [['key' => '统计数', 'values' => $gdata]]; $app->render('console/stat_visitor.html', array('day' => $day, 'range' => $range, 'count' => $count, 'type' => 'visitor', 'data' => $data, 'table' => $table, 'gdata' => json_encode($gdata))); })->name('stat_visitor'); $app->get('/stat/source', function () use($app) { $env = $app->environment(); $user = $env['user']; $req = $app->request(); $day = $app->request->get('day'); $day = $day ? $day : date('Y-m-d'); $range = dayrange(); $count = count_num($day, ['siteid' => $user->siteid]); $page = $req->get("page") == null ? 1 : $req->get("page"); $table = new \Slim\Admin\Table('visitors', '地理统计'); $urlVis = $app->urlFor('visitors'); $table->column('day', '天')->config('range', '--')->config('disabled', true); $table->column('location', ['label' => '来源', "formatter" => function ($t, $col, $row, $val) use($urlVis) { return array("link", $val, $t->urlForLink($urlVis, array('location' => $val))); }]); $table->column('location_num', '次数'); $table->groupby('location'); $table->sort('location_num'); $table->conditions(['day' => $day, 'siteid' => $user->siteid]); $data = $table->data($page); $app->render('console/stat_source.html', array('day' => $day, 'range' => $range, 'count' => $count, 'type' => 'source', 'data' => $data, 'table' => $table)); })->name('stat_source'); /**