|
 |
|
จะดึงข้อมูลบางตัวออกจากตัวแปลแบบ array ทำอย่างไงครับ |
|
 |
|
|
 |
 |
|
<?
$prd = array ("prd01" => array (
"code" => "w01",
"price" => "8,600"
),
"prd02" => array (
"code" => "w02",
"price" => "5,500"
),
"prd03" => array (
"code" => "w03",
"price" => "8,800"
),
"prd04" => array (
"code" => "v01",
"price" => "1,500"
),
"prd05" => array (
"code" => "v02",
"price" => "1,500"
),
"prd06" => array (
"code" => "v03",
"price" => "1,500"
),
"prd07" => array (
"code" => "b01",
"price" => "2,800"
),
"prd08" => array (
"code" => "b02",
"price" => "1,200"
),
"prd09" => array (
"code" => "b03",
"price" => "1,450"
),
"prd10" => array (
"code" => "s01",
"price" => "1,800"
),
"prd11" => array (
"code" => "s02",
"price" => "2,500"
),
"prd12" => array (
"code" => "s03",
"price" => "2,600"
),
);
?>
นี้คือตัวแปลแบบ array ถ้าต้องการดึงข้อมูลบางตัวออกมา ต้องทำไงครับ เช่น
ดึงข้อมูลเฉพาะ price ออกมาอย่างเดียวต้องการไงครับ
ตัวอย่าง
8,600
5,500
8,800
1,500
1,500
1,500
2,800
1,200
1,450
1,800
2,500
2,600
ช่วยหน่อยนะครับ
Tag : - - - -

|
|
 |
 |
 |
 |
Date :
2009-02-28 17:54:48 |
By :
บอย |
View :
1219 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
<?
foreach($prd as $val){
if( is_array($val) )
foreach( $val as $key=>$val2 )
if($key == 'price') echo $val2, '<br>';
}
?>
SITE: http://gunner.freetzi.com
MSN: [email protected]
TEL: 087-577-0276
|
 |
 |
 |
 |
Date :
2009-02-28 19:04:26 |
By :
pjgunner |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
<?
foreach($prd as $product){
echo $product["price"] '<br>';
}
?>
|
 |
 |
 |
 |
Date :
2009-02-28 23:55:59 |
By :
plakrim |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 04
|