I have a strange PHP array issue which I am really confused about... I'm using PHP to take a stash array from within ExpressionEngine, make sure the values are unique, and then using array_intersect to compare to another array - for test purposes the arrays have identical values...
<?php
$faves = '{exp:stash:get name="skills" scope="user"}';
$faves = rtrim($faves, "|");
$allfavourites = explode('|', $faves);
$allfavourites = array_unique($allfavourites);
$this_barristers_fave_ids = array(6,7,8,9,10,11,12,13,14,15,16,17,4,5,3,1,2);
echo "<br/>There are <strong>".sizeof($allfavourites)."</strong> skills in the faves array after being made unique";
$num = count(array_intersect($finalfaves, $this_barristers_fave_ids));
echo "<br/><br/>num is ".$num; // this outputs '13' ?>
The hardcoded '$this_barristers_fave_ids' has exactly the same contents as the $allfavourites array (17 values), so I am expecting the $num variable to output '17'. If I output $faves on about line 3 before exploding it, the output is exactly the contents of the hardcoded '$this_barristers_fave_ids' - I am so confused as to why the number I am getting outputted is 13 instead of 17 - am I missing a stage after the explode and the array_unique that somehow normalises the array and so I will get the number expected?
I'd be so grateful as always for any help...
Many thanks!