FInding duplicate value in PHP array -
this question has answer here:
[0] => array ( [id] => 9 [order_address_id] => 9 [created] => 2015-12-17 12:24:20 [order_status] => dispatched [total_discount] => [total_shipping_charge] => 60 [s_state] => ny [b_state] => ny [order_id] => 9 [p_name] => product 1 [qty] => 1 [price] => 475 ) [1] => array ( [id] => 9 [order_address_id] => 9 [created] => 2015-12-17 12:24:20 [order_status] => dispatched [total_discount] => [total_shipping_charge] => 60 [s_state] => ma [b_state] => ma [order_id] => 9 [p_name] => product 2 [qty] => 1 [price] => 349 )
i want find if array same id repeats have delete total_shipping_charge second , subsequent array having same id. how can in php?
i use array_walk this.
first, want create callback function checks if id has been encountered, , unsets total_shipping_charge
if has, like
function shipping_charge_walk(&$entry, $key, &$found_ids) { if (in_array($entry['id'], $found_ids)) { unset($entry['total_shipping_charge']); } else { $found_ids[] = $entry['id']; } }
this takes $found_ids
reference, can append encountered ids it, , takes $entry
reference can unset member of it.
then, call array walk on array.
$found_ids = array(); array_walk($arr, 'shipping_charge_walk', $found_ids);
Comments
Post a Comment