-2

我的数组结构是

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);
4

3 回答 3

5
echo $data['customer_id'][0]['customer_id'];
于 2012-05-15T10:37:19.613 回答
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;
?>
于 2012-05-15T10:44:02.297 回答
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
?>
于 2012-05-15T11:36:22.290 回答