麗山七老
$str = '1,2,3,4,1,23,54,12,3221,2,1,3';$arr = explode(',', $str);echo implode(',',array_keys(array_count_values($arr)));錯的
話說你真的試了么,你這個字符串有點特殊,不需要排序結(jié)果也沒錯
//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));//重復的次數(shù),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數(shù)據(jù)庫的話,查詢的時候 加入排序語句就可以了例如 select * from tablename where 1=1 order by a desc limit 0,5;order by a desc 的意思就是按照a從大到小的順序排列l(wèi)imit表示的是從結(jié)果的第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.要是用到數(shù)據(jù)庫的話還需要安裝mysql。然后在www里放以。php結(jié)尾的文件就可以訪問。還是輸入localhost當然前提是你的php語法正確
姬志真
PHP根據(jù)數(shù)組的值分組,php array中沒有自帶這個函數(shù)但是很常用代碼:$_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();//這里把簡直轉(zhuǎn)成了數(shù)字的,方便同意處理foreach ($result as $key => $value) {array_push($ret, $value);}return $ret;}運行結(jié)果如下: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 下構(gòu)造你的sql查詢語句就行了,這個實現(xiàn)方法比較簡單,但是還有一些不完美的地方,比如 order=$order_next 這個做法并不好,我主要是給你提個我的思路,如果你需要一個更完美的功能,那你就再自己去優(yōu)化完善一下吧。
張柏林
<?php $source = array('a' => '111', 'b' => '222', 'c' => '33333', 'd' => '4444'); $needKey = array('a', 'c'); $needKey = array_flip($needKey); //調(diào)轉(zhuǎn)鍵值使之可比。array('a'=>0, 'c'=>1) $array = array_intersect_ukey($source,$needKey,'key_compare_func'); //array_intersect_ukey用回調(diào)函數(shù)比較鍵名來計算數(shù)組的交集 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>
(是字符串類型)
并非是屏幕寬度(數(shù)字類型)
你拿一個字符串和數(shù)字做大小比較,在if語句中,肯定會一直執(zhí)行最后那個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);