Home > Backend Development > PHP Tutorial > 数组统计问题

数组统计问题

WBOY
Release: 2016-06-23 13:21:46
Original
961 people have browsed it

 请问怎么实现判断有多少个访问成功200 有多少个访问失败404


回复讨论(解决方案)

$a = array(  array('mode' => '  200 47 '),  array('mode' => '  200 47 '),  array('mode' => '  404 47 '),  array('mode' => '  404 47 '),  array('mode' => '  200 47 '),);foreach($a as $t) {  @$res[intval($t['mode'])]++;}print_r($res);
Copy after login
Copy after login
Array(    [200] => 3    [404] => 2)
Copy after login
Copy after login

$arr = array(array('mode'=>'404 47'),array('mode'=>'200 47'),array('mode'=>'404 47'));$i = 0;$x = 0;$y = 0;while($i<count($arr)){    $a = explode(' ',$arr[$i]['mode']);    if($a[0]=='404'){        $x = $x + 1 ;    }elseif($a[0]=='200'){        $y = $y + 1;    }    $i++;}echo '404:'.$x,',200:'.$y;
Copy after login

我初学者,

$a = array(  array('mode' => '  200 47 '),  array('mode' => '  200 47 '),  array('mode' => '  404 47 '),  array('mode' => '  404 47 '),  array('mode' => '  200 47 '),);foreach($a as $t) {  @$res[intval($t['mode'])]++;}print_r($res);
Copy after login
Copy after login
Array(    [200] => 3    [404] => 2)
Copy after login
Copy after login

谢谢大神!!
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template