Is it possible to compare a string vs. a string one level deeper (in an array) using array_uintersect()? Or will there be some sorting taking place and those params be swapped behind the scenes when serving them to the value compare function (callback)?
The purpose is to remove duplicates from $urls.
$urls:Array
(
[0] => Array
(
[url] => https://www.example.com/
[parent_url] => https://www.example.com/bleh/bleh.aspx
)
[1] => Array
(
[url] => https://www.example.com/
[parent_url] => https://www.example.com/bla/bla.aspx
)
)
$urls_uniq: Array
(
[1] => https://www.example.com/
[2] => https://www.example.com/go/173.aspx
)
function compareDeepValue($val1, $val2)
{
if (is_array($val1) && empty($val1)){
return 0;
}
// here I assume val1 is always an array (elements
// from $urls) and val2 is always a string (elements from urls_uniq)
return strcmp($val1['url'], $val2);
}
$intersect = array_uintersect($urls, $urls_uniq, 'compareDeepValue');
It gives me this error at the callback function (swapping vars does not help):
strcmp(): Argument #1 ($string1) must be of type string, array given
The
strcmpfunction requires string parameters for comparison.Do all instances of a
urlin$urlsfrom$urls_uniqneed to be removed, or should there just be 1 instance regardless of theparent_url?If
array_uintersectis absolutely necessary, I'd try===comparisons instead ofstrcmp.