I have an issue with in_array not returning true even though duplicates are in an array. After doing some research on this site, I found that a lot of Windows users have issues due to invisible line breaks \r\n etc., but this seems to not be the case because after printing the length of each string, it matches with what I have (no invisible characters). Still, my code seems to be unable to match new values with what's already in the array:
<?php
$XMLName = "file.xml";
$XMLFile = simplexml_load_file($XMLName);
$categories = array();
$i = 0;
foreach($XMLFile as $ReadFile) {
$cat = $ReadFile->CategoryName;
$IsInArray = in_array($cat, $categories);
if($IsInArray == FALSE) {
$categories[$i] = $cat;
$i++;
}
}
foreach($categories as $category) {
echo $category . "<br />";
}
?>
Does anyone have a clue why this is the case?
No comments:
Post a Comment