[1] => 天津 [2] => 北京 )  Array ( [0] => [1] => 北京 [2] => 上"/> [1] => 天津 [2] => 北京 )  Array ( [0] => [1] => 北京 [2] => 上">

php 数组有关问题

WBOY
Release: 2016-06-13 10:33:40
Original
731 people have browsed it

php 数组问题
$abc是从数据库中循环出来的
$pieces = explode("|", $abc);
print_r($pieces);
打印结果是
Array ( [0] => [1] => 天津 [2] => 北京 ) 
Array ( [0] => [1] => 北京 [2] => 上海 [3] => 河北 ) 
Array ( [0] => [1] => 天津 [2] => 河北 [3] => 北京 )
我想知道 天津、河北、北京、上海,各出现次数是多少。
好像不能用这个array_intersect()

------解决方案--------------------
先把数组合并 在用 array_count_values 

PHP code
<?php $array = array(1, "hello", 1, "world", "hello");print_r(array_count_values ($array));?><br><font color="#e78608">------解决方案--------------------</font><br>$array_count = array();//不能放你循环里,初始化1次<br>foreach($pieces as $v){<br>   if(!empty($v)){<br>       if(empty($array_count[$v])){<br>           $array_count[$v] = 1;<br>       }else{<br>           $array_count[$v] += 1;<br>       }<br>   }<br>}<br><br>$pieces 是每次循环打断出来的。<div class="clear">
                 
              
              
        
            </div>
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