I have a multidimensional array in PHP that takes the following form:
$data = array(
array('spot'=>1,'name'=>'item_1'),
array('spot'=>2,'name'=>'item_2'),
array('spot'=>1,'name'=>'item_3'),
);
If more than one element of the array contains a duplicate for the number "spot", I would like to randomly select one and delete all other elements with the same value "spot". What would be the most efficient way to accomplish this? The resulting array will look like this:
$data = array(
array('spot'=>2,'name'=>'item_2'),
array('spot'=>1,'name'=>'item_3'),
);
source
share