$str = '1,2,3,4,1,23,54,12,3221,2,1,3';$arr = explode(',', $str);echo implode(',',array_keys(array_count_values($arr)));
错的
话说你真的试了么,你这个字符串有点特殊,不需要排序结果也没错
//1,2,3,4,23,54,12,3221 //上面三行的输出$str = '1,2,3,4,1,23,54,12,3221,2,1,3';$arr = array_count_values(explode(',', $str));//重复的次数,Array ( [1] => 3 [2] => 2 [3] => 2 [4] => 1 [23] => 1 [54] => 1 [12] => 1 [3221] => 1 ) $arr = array_keys($arr); sort($arr);echo implode(',',$arr);//1,2,3,4,12,23,54,3221 //排过序的输出
如果是mysql数据库的话,查询的时候 加入排序语句就可以了例如 select * from tablename where 1=1 order by a desc limit 0,5;order by a desc 的意思就是按照a从大到小的顺序排列limit表示的是从结果的第0个值开始获取前5个值。
1.你输入localhost显示的是it work!吧?这只是说明你的apache启动了。2.想加HTML或者php文件的话还要对apache的配置文件进行修改。DocumentRoot "D:/local/www" //指向www目录 php文件放里面 LoadModule php5_module D:\local\php5\php5apache2_2.dll PHPIniDir "D:\local\php5\php.ini" AddType application/x-httpd-php .php //开启php扩展 DirectoryIndex index.html index.php index.html.var index.htm然后重启apache再试试3.要是用到数据库的话还需要安装mysql。然后在www里放以。php结尾的文件就可以访问。还是输入localhost当然前提是你的php语法正确
PHP根据数组的值分组,php array中没有自带这个函数但是很常用代码:$_array = array(array(1,11,'2016-05-18'),array(2,11,'2016-05-18'),array(3,22,'2016-05-18'),array(4,22,'2016-05-18'),array(5,33,'2016-05-19'),array(6,33,'2016-05-19'),array(7,44,'2016-05-19'),array(8,44,'2016-05-19'),array(9,55,'2016-05-20'),array(10,55,'2016-05-20'),);var_dump(array_val_chunk($_array));function array_val_chunk($array){$result = array();foreach ($array as $key => $value) {$result[$value[1].$value[2]][] = $value;}$ret = array();//这里把简直转成了数字的,方便同意处理foreach ($result as $key => $value) {array_push($ret, $value);}return $ret;}运行结果如下:array(5) {[0]=>array(2) {[0]=>array(3) {[0]=>int(1)[1]=>int(11)[2]=>string(10) "2016-05-18"}[1]=>array(3) {[0]=>int(2)[1]=>int(11)[2]=>string(10) "2016-05-18"}}[1]=>array(2) {[0]=>array(3) {[0]=>int(3)[1]=>int(22)[2]=>string(10) "2016-05-18"}[1]=>array(3) {[0]=>int(4)[1]=>int(22)[2]=>string(10) "2016-05-18"}}[2]=>array(2) {[0]=>array(3) {[0]=>int(5)[1]=>int(33)[2]=>string(10) "2016-05-19"}[1]=>array(3) {[0]=>int(6)[1]=>int(33)[2]=>string(10) "2016-05-19"}}[3]=>array(2) {[0]=>array(3) {[0]=>int(7)[1]=>int(44)[2]=>string(10) "2016-05-19"}[1]=>array(3) {[0]=>int(8)[1]=>int(44)[2]=>string(10) "2016-05-19"}}[4]=>array(2) {[0]=>array(3) {[0]=>int(9)[1]=>int(55)[2]=>string(10) "2016-05-20"}[1]=>array(3) {[0]=>int(10)[1]=>int(55)[2]=>string(10) "2016-05-20"}}}
<?php$sort = $_GET['sort'];$order = $_GET['order'];$order=='' && $order='asc';$order_next=($order=='asc'?'desc':'asc');switch($sort) { case 'id': echo 'SORT BY ID<br>'; echo 'ORDER is '.$order; break; case 'name': echo 'SORT BY NAME<br>'; echo 'ORDER is '.$order; break; case 'date': echo 'SORT BY DATE<br>'; echo 'ORDER is '.$order; break; default: echo 'WHAT ARE U DOING ??';}?><p><a href="?sort=id&order=<?php echo $order_next; ?>">ID</a><br/><a href="?sort=name&order=<?php echo $order_next; ?>">NAME</a><br/><a href="?sort=date&order=<?php echo $order_next; ?>">DATE</a><br/></p> 你只需要在每个 CASE 下构造你的sql查询语句就行了,这个实现方法比较简单,但是还有一些不完美的地方,比如 order=$order_next 这个做法并不好,我主要是给你提个我的思路,如果你需要一个更完美的功能,那你就再自己去优化完善一下吧。
<?php $source = array('a' => '111', 'b' => '222', 'c' => '33333', 'd' => '4444'); $needKey = array('a', 'c'); $needKey = array_flip($needKey); //调转键值使之可比。array('a'=>0, 'c'=>1) $array = array_intersect_ukey($source,$needKey,'key_compare_func'); //array_intersect_ukey用回调函数比较键名来计算数组的交集 var_dump($array); function key_compare_func($key1, $key2){ if ($key1 == $key2) return 0; else if ($key1 > $key2) return 1; else return -1; }//End_php
这段代码当然没有效果咯
因为变量width的值是
<script language=\"javascript\">document.write(window.screen.width);</script>
(是字符串类型)
并非是屏幕宽度(数字类型)
你拿一个字符串和数字做大小比较,在if语句中,肯定会一直执行最后那个else的部分的
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"><form method="get" id="f"> <input type="hidden" name="w" id="w" value=""> <input type="hidden" name="h" id="h" value=""></form><?phpif($_GET['w'] && $_GET['h']){ echo '屏幕宽度为'.$_GET['w'].',高度为'.$_GET['h'];}else{?><script>window.onload=function(){ document.getElementById('w').value = window.screen.width; document.getElementById('h').value = window.screen.height; document.getElementById('f').submit();}</script>';<?php}?>
思路没有错,然后铺页面就行
$arr = array('a'=>1,'c'=>3,'b'=>2);asort($arr);