note 129022 added to function.sort

From: Date: Thu, 09 Nov 2023 12:36:20 +0000
Subject: note 129022 added to function.sort
Groups: php.notes 
Request: Send a blank email to php-notes+get-220978@lists.php.net to get a copy of this message
<?php //sort an array if alphanum mixing value $input = array( '0' => 'z1', '1' => 'Z10', '2' => 'z12', '3' => 'Z2', '4' => 'z3', ); for ($i = 0; $i < count($input) - 1; $i++) { for ($j = 0; $j < count($input) - 1 - $i; $j++) { if (substr($input[$j + 1], 1) > substr($input[$j], 1)) { $temp = $input[$j + 1]; $input[$j + 1] = $input[$j]; $input[$j] = $temp; } } } $arr = array(2,5,1,7,4); $count = count($arr); for($i=0;$i<=$count-1 ;$i++){ for($j =0; $j < $count-1 ;$j++){ if($arr[$j+1] < $arr[$j]){ $temp = $arr[$j+1]; $arr[$j+1] = $arr[$j] ; $arr[$j] = $temp; } } } echo "<pre>"; print_r($arr); echo "<hr>"; echo "2<b> sorting array without function</b>"; $data = [ 'A','C','D','B','Z','P']; $count = count($data); for($i=0; $i<$count-1; $i++){ for($j=0; $j< $count-1 ;$j++){ if(ord($data[$j +1]) < ord($data[$j])){ $temp = $data[$j+1]; $data[$j+1] = $data[$j] ; $data[$j] = $temp; } } } print_r($input); ?> ---- Server IP: 45.112.84.4 Probable Submitter: 45.91.157.134 (proxied: 2409:4081:2c1e:ce8f:696d:6fbd:67c9:153a) ---- Manual Page -- https://php.net/manual/en/function.sort.php Edit -- https://main.php.net/note/edit/129022 Del: integrated -- https://main.php.net/note/delete/129022/integrated Del: useless -- https://main.php.net/note/delete/129022/useless Del: bad code -- https://main.php.net/note/delete/129022/bad+code Del: spam -- https://main.php.net/note/delete/129022/spam Del: non-english -- https://main.php.net/note/delete/129022/non-english Del: in docs -- https://main.php.net/note/delete/129022/in+docs Del: other reasons-- https://main.php.net/note/delete/129022 Reject -- https://main.php.net/note/reject/129022 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#220978) next »