|
 |
|
รบกวนช่วยดูโค้ด การไล่ ตัวเลขมากไปหาน้อยกับน้อยไปหามากว่าถูกหรือเปล่าครับ |
|
 |
|
|
 |
 |
|
จะเอาเลขที่ป้อนเข้ามาแล้วแยกว่าป็น คู่ รึ คี่ พร้อมทั้ง เรียงลำดับ ใช่มั้ยครับ
Code (PHP)
<?php
$var = isset($_GET['g'])?$_GET['g']:"123456789";
$arr = str_split($var);
$arr_odd = array();
$arr_even = array();
foreach($arr as $val)
{
if($val %2 == 0)
{
$arr_even[] = $val;
}
else
{
$arr_odd[] = $val;
}
}
sort($arr_odd);
rsort($arr_even);
echo "Odd = ".implode(" ",$arr_odd);
echo "Even = ".implode(" ",$arr_even);
?>
|
 |
 |
 |
 |
Date :
2009-08-09 17:53:43 |
By :
lozomac |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คือว่าจะทำแยกกันหนะครับ จะทำ แยก เรียงมากไปหาน้อยกับน้อยไปหามาก อย่างละตัวหนะครับ ไม่จำเป็นต้องใช้เลขคี่หรือคู่หนะครับ คือจะรับค่ามาจาก $var = $_REQUEST['g']; หนะครับพอชี้แนะหน่อยได้ไหมครับ ผมยังงงมากเลยครับ แบบว่าเราไม่ต้องมา
กำหนด
<?php
$var = $_REQUEST['g'];
$var=array(”4”,”2”,”4”,”8”,”6”); <<< นี่หนะครับ ไม่อยากกำหนด อยากใส่ค่าเองหนะครับ ทั้งสอง โค้ดหนะครับ พอจะช่วยชี้แนะได้ไหมครับ !
rsort($var);
for ($i=0;$i<=count($var)-1;$i++){
echo $var[$i].”<br>”;
}
?>
|
 |
 |
 |
 |
Date :
2009-08-09 18:19:06 |
By :
iruka1258 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เพราะว่า หน้าแรก เป็นหน้า g หนะครับรับค่ามา ประมวลผลใน หน้า h คือโค้ดหนิแหละครับ
อยากทำแบบ น้อยไปหามาก กับมากไปหา น้อยแยกกันหนะครับ โดยกรอกเลขไป โดยเราไม่ต้องกำหนดนะครับ
|
 |
 |
 |
 |
Date :
2009-08-09 18:30:08 |
By :
iruka1258 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ออ ครับ
Code (PHP)
<?php
$var = isset($_GET['g'])?$_GET['g']:"123456789";
$arr = str_split($var);
sort($arr);
$arr1 = $arr;
rsort($arr);
$arr2 = $arr;
echo "น้อยไปมาก = ".implode(" ",$arr1);
echo "มากไปน้อย = ".implode(" ",$arr2);
?>
|
 |
 |
 |
 |
Date :
2009-08-10 14:36:02 |
By :
lozomac |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Fatal error: Call to undefined function: str_split() in c:\appserv\www\yu\h.php on line 4 มันมีปัญหาตรงนี้หนะครับ !
|
 |
 |
 |
 |
Date :
2009-08-10 20:29:10 |
By :
iruka1258 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เหมือนคำสั่งหรือชื่อมันประกาศผิดหรือเปล่าครับ !
|
 |
 |
 |
 |
Date :
2009-08-10 20:29:35 |
By :
iruka1258 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 04
|