Hey guys,
I have the following array (I have shortened it to make it more readable):
Array
(
[0] => Array
(
[opportunity_item] => Array
(
[id] => 3027
[opportunity_id] => 99
[item_id] =>
[item_type] =>
[opportunity_item_type] => 0
[opportunity_item_type_name] => Group
[name] => Lighting
[transaction_type] =>
[transaction_type_name] =>
[accessory_inclusion_type] =>
[accessory_inclusion_type_name] =>
[accessory_mode] =>
[accessory_mode_name] =>
[status] =>
[status_name] =>
[quantity] => 0.0
[revenue_group_id] =>
[rate_definition_id] =>
[service_rate_type] =>
[service_rate_type_name] =>
[price] => 0.0
[discount_percent] => 0.0
[starts_at] =>
[ends_at] =>
[use_chargeable_days] =>
[chargeable_days] => 0.0
[sub_rent] =>
[path] => 0001
[description] =>
[rental_charge_total] => 70.0
[sale_charge_total] => 0.0
[surcharge_total] => 0.0
[service_charge_total] => 0.0
[tax_total] => 14.0
[replacement_charge_total] => 15.0
[weight_total] => 10.7
[unit_base_charge] => 0.0
[unit_charge] => 0.0
[charge_amount] => 0.0
[taxable_charge_amount] => 0.0
[tax_amount] => 0.0
[surcharge_amount] => 0.0
[surcharge_tax_amount] => 0.0
[charging_periods] =>
[replacement_charge] => 0.0
[weight] => 0.0
[charge_total] => 70.0
[charge_total_including_children] => 70.0
[weight_total_including_children] => 10.7
[replacement_charge_total_including_children] => 15.0
[charge_excluding_tax_total] => 70.0
[charge_including_tax_total] => 84.0
[lead_charging_period] =>
[lead_charging_period_name] =>
[custom_fields] => Array
(
)
[revenue_group] =>
[rate_definition] =>
[item_assets] => Array
(
)
[item_surcharges] => Array
(
)
)
[meta] => Array
(
[can_edit?] => 1
[can_destroy?] => 1
)
)
[1] => Array
(
[opportunity_item] => Array
(
[id] => 3028
[opportunity_id] => 99
[item_id] => 127
[item_type] => Product
[opportunity_item_type] => 1
[opportunity_item_type_name] => Principal
[name] => Robe Robin 600 LED Wash
[transaction_type] => 1
I want to get rid of the rubbish out of this array, and create a new version which I can then work with to present in a neat format. To work through it I have been trying to use a for each loop like the one below:
//$new_obj is the array containing all the info
$items_array = array();
foreach ($new_obj as $new_key) {
foreach ($new_key as $new_id) {
echo $item_name = $new_id['name'];
}
}
This works, kind of except that it gives me double results, with half of them not working:
Robe Robin 600 LED Wash11.0
Notice: Undefined index: name in /home/linweb30/z/zeallive.com/user/htdocs/api/index.php on line 82
I'm guessing this is something to do with the double for each loops? I have tried to use this code instead
foreach ($new_obj as $new_key => $new_id) {
echo $item_name = $new_id['name'];
}
But that can't find the array index. Could you help please?
Thanks
Andy