|
 |
|
การหาตำแหน่งในค่าarray ทำไงดีครับ พอดีผมมี ค่าใน array จำนวน 5ค่า เช่น array("5","20","10","21","30") |
|
 |
|
|
 |
 |
|
PHP Array
|
 |
 |
 |
 |
Date :
2009-11-16 11:13:29 |
By :
panyapol |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไม่แน่ใจว่าจะมีฟังก์ชันเปล่าน่ะ แต่เราก็สามารถเขียนถึกๆเลยก็ได้แง่มๆ  
Code (PHP)
$a =array("5","20","10","21","30")
foreach($a as $key=>$val){
if($val=='10'){
echo $key;
break;
}
}
|
 |
 |
 |
 |
Date :
2009-11-16 11:15:19 |
By :
xbeginner01 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ถ้าหาคีย์ของ array ใช้ตัวนี้เลยคับ
Code (PHP)
$array = array("5","20","10","21","30");
echo array_search("10",$array);
|
 |
 |
 |
 |
Date :
2009-11-16 11:24:24 |
By :
หางอึ่ง |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
Load balance : Server 05
|