My array structure is
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
)
I need to get the value of [customer_id] => 123
. Tell me how can I do that?
Still my problem is not solved so I am posting code:
$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);
Just go through your array step by step until you are at the needed property.
$arr[ 'id' ][ 0 ][ 'customer_id' ]
Either
$array["id"][0]["customer_id"]
or if you want to get all customers' ids, use foreach
foreach($array["id"] as $index => $data) {
$customer_id = $data["customer_id"]
}
There are two approach to get the value of customer_id.
1. If you array is dynamic and you are not sure, what will be the key value, you can use key or array_keys function of php. Then you can retrieve it.
array['id'][$key]['customer_id']
for multiple keys, you can use foreach loop.
2.If is static array, then you can get it direct.
array['id'][0]['customer_id']