Stripping out duplicate values
array array_unique ( array input)
Consider if the $toppings2 array had been declared like this:
$toppings2 = array("Peppers", "Ham", "Cheese", "Peppers");
In this situation, there'd be two Peppers elements in there, in which case we would want to strip out the duplicate Peppers before running the merges and intersects. This is done by using array_unique(), which takes an array as its parameter and returns the same array with its duplicate values removed, like this:
$toppings2 = array_unique($toppings2);
Try the example code again, this time removing the duplicate Cheese values from $bothtoppings.
Next chapter: Filtering your array through a function >>
Previous chapter: Chopping and changing arrays
Jump to:
Home: Table of Contents



Copyright 2012 Future Publishing Limited (company
registered number 2008885), a company registered
in England and Wales whose registered office is at
Beauford Court, 30 Monmouth Street, Bath, BA1 2BW, UK