This is the $feed_content array
Array
(
[0] => Array
(
[id] => 1
[link] => http://www.dust-off.com/10-tips-on-how-to-love-your-portable-screens-keeping-them-healthy
)
[1] => Array
(
[id] => 2
[link] => http://www.dust-off.com/are-you-the-resident-germaphobe-in-your-office
)
)
—-Another array———-
This is the $arrFeeds array
Array
(
[0] => Array
(
[title] => 10 Tips on How to Love Your Portable Screens (Keeping them Healthy)
[link] => http://www.dust-off.com/10-tips-on-how-to-love-your-portable-screens-keeping-them-healthy
)
[1] => Array
(
[title] => Are You the Resident Germaphobe in Your Office?
[link] => http://www.dust-off.com/are-you-the-resident-germaphobe-in-your-office
)
)
Here’s my code:
foreach( $arrFeeds as $key2 => $value2 )
{
$feed_content = $feed->get_feed_content( $value['id'] );
if( !in_array( $value2['link'], $feed_content ) )
{
echo "not match!";
}
}
Question:
Why is it that the code always enters into the if statement even if $feed_content link value has the value of the $arrFeeds link?
My expected result should be that my code would tell me if the $feed_content link value is not in the $arrFeeds.
By the way, the $feed_content code returns an array that I specified above.
What should be the problem with this one. Thanks in advance! 🙂
that’s because the elements of your array called $feed_content are associative arrays also (with the id and link keys)
you are checking if the link (a string) is equal to any of the elements in the array (all of them arrays)
Edit:
To achieve what you want you can use a “hack”. Instead of in_array you can use something like:
this thing relies on the fact that you can use an array for the search needle for the array_search function and that the comparison won’t be strict, so true will match any number (except 0, but I guess that you don’t use 0 as an id)
this way the only field that will really matter is the one for the link
after that you need to use a strict comparison this time to be sure that if the found key is 0 you will use it