Last active
December 17, 2015 16:09
-
-
Save alancoleman/5636496 to your computer and use it in GitHub Desktop.
Function to walk through a multidimensional array and remove any successive duplicates based on an index
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Function to walk through a multidimensional array and remove any successive duplicates based on an index | |
function stripDuplicateHeader(&$stripArray, $index){ // Pass a reference of the array to be processed and the index to check | |
$newArr = array(); // Create an array in which to populate the processed arrays | |
foreach (array_reverse($stripArray) as $val) { // walk through the array to be processed backwards | |
$newArr[$val[$index]] = $val; //populate | |
} | |
$stripArray = array_reverse(array_values($newArr)); // remove duplicates | |
return $stripArray; // Return array | |
} | |
// Call function to strip duplicate headers | |
$header = stripDuplicateHeader($header, 'field'); | |
//var_dump($header); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment