我的数组结构是
Array
(
[customer_id] => Array
(
[0] => Array
(
[customer_id] => 123
)
)
[menu_item_net_price] => 1700
[menu_item_tax_price] => 4%
[menu_item_gross_price] => 1700
[provider_id] => 123
)
我需要获得[customer_id] => 123
的值。告诉我该怎么做?
我的问题仍未解决,因此我发布了代码:
$data['customer_id'] = $this->session->userdata('id');
$data['menu_item_net_price']= $netPrice;
$data['menu_item_tax_price']= '4%';
$data['menu_item_gross_price']= $netPrice;
$data['provider_id']= 123;
echo '<pre>';
print_r($data);
echo '</pre>';
exit(0);
答案 0 :(得分:5)
echo $data['customer_id'][0]['customer_id'];
答案 1 :(得分:1)
如果要保留数组的格式,可以这样做:
<?php
$data['customer_id'] = $this->session->userdata('id');
$data['customer_id'] = $data['customer_id'][0]['customer_id'];
$data['menu_item_net_price']= $netPrice;
$data['menu_item_tax_price']= '4%';
$data['menu_item_gross_price']= $netPrice;
$data['provider_id']= 123;
?>
答案 2 :(得分:0)
如果您更改阵列的格式,则很简单:
<?php
$data[$this->session->userdata('id')]['menu_item_net_price']= $netPrice;
$data[$this->session->userdata('id')]['menu_item_tax_price']= '4%';
$data[$this->session->userdata('id')]['menu_item_gross_price']= $netPrice;
$data[$this->session->userdata('id')]['provider_id']= 123;
echo $data[$customer_id]['provider_id']; //echoes 123
?>