Skip to content
Advertisement

If str_ireplace() doesn’t meet php condition

I have a code where I match comma-separated words to text using the str_ireplace() function:

JavaScript

Please tell me how can I do the reverse logic? Those. if nothing is found or matched.

else {} does not work.

Full code:

JavaScript

Advertisement

Answer

The problem is that you’re adding the default categories whenever you don’t match the keywords in one element of $correspondence_tables, but it could match later elements.

The code to add the default categories should only be added if none of the keywords in $correspondence_tables are matched. You can tell if that happened at the end of the loop by checking if $arr_cat is empty.

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement