|
 |
|
ถามเรื่องการวนรอบ array แบบ foreach หาค่าที่อยู่ถัดไปเพื่อเช็ค if |
|
 |
|
|
 |
 |
|
ลืมบอก..
สัญลักษณ์ ' > ' มาจากตัว $this->symbool; นะครับ
ในคลาสจะกำหนดไว้ว่า
Code (PHP)
<?php
var $symbol = " > ";
?>
|
 |
 |
 |
 |
Date :
2009-09-22 22:50:27 |
By :
mr.v |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ถ้าใช้ loop foreach รู้สึกจะไม่มี function แบบนั้นครับ เอาแบบพื้นฐานละกันครับ 
$a = array('k1'=>'v1','k2'=>'v2','k3'=>'v3');
$c = count($a);
foreach($a as $k=>$v){
echo "$k";
if (--$c){
echo '>';
}
}
|
 |
 |
 |
 |
Date :
2009-09-22 23:18:34 |
By :
num |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
good ครับ
|
 |
 |
 |
 |
Date :
2009-09-22 23:23:59 |
By :
mr.v |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
-1 ครับพี่หนุ่ม เอ๊ย +1 คร๊าบบบบบ
|
 |
 |
 |
 |
Date :
2009-09-22 23:28:25 |
By :
NanoTHoro |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
<?php
$output = array();
$input = array("home"=>"/","category"=>"/category/","product"=>"/category/product/");
foreach ($input as $key => $val) {
$output[] = html::a($key,$val);
}
$output = implode( $this->symbol, $output);
?>
ชอบจิงๆ implode เนี้ย 
|
 |
 |
 |
 |
Date :
2009-09-23 02:00:17 |
By :
danya |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อืม ตามดุนยา นั่นละครับ
|
 |
 |
 |
 |
Date :
2009-09-23 08:06:14 |
By :
lozomac |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 03
|