$almostallTech=array();
$almostallTech[]="no";
$almostallTech[]="no";
$almostallTech[]="yes";
$almostallTech[]="yes";
$almostallTech[]="no";
$almostallTech[]="yes";
$almostallTech=array_unique($almostallTech);
printf("size of array: %d<br/>", sizeof($almostallTech));
for ($x = 0; $x < (sizeof($almostallTech)); $x++) {
printf("%s", $almostallTech[$x]);
}
After calling the unique method, it returns the size is 2 - which is correct. However the for loop is giving an undefined offset error.
Upon further checking, if I print out:
printf("%s", $almostallTech[0]); - I get no
printf("%s", $almostallTech[2]); - I get yes
printf("%s", $almostallTech[1]); - undefined offset error
So the unique function is removing duplicates but keeping the same index of the former array - which is how it works. This should be simple but can't figure out how to remove the empty or more specifically undefined indexes. Tried the array_filter but still not working. Any suggestions?
What I want is after calling the array_unique method, the duplicates are removed but new indexes should apply. i.e.: I want $almostallTech[0] to contain "no" I want $almostallTech[1] to contain "yes"
array_unique(). Read the manual: php.net/function.array-unique