PHP Warning: in_array() expects parameter 2 to be array

Created At: 2024-03-24 00:32:58 Updated At: 2024-03-24 00:34:38

I am still running my old website in PHP. Not this official website though. All of my websites are built in PHP.

Anyway, my 9 year old PHP website throw an error lately since the upgrade of PHP.

So as you see we hit an error and the website just crushed. Even though on line 77 v['p_id'] and $medieclass are arrays. 

But it sill crashes. After debugging I found that $medieclass come as null values. That's why in_array() function crashes.

Since $medieclass contains some null values, then we need to avoid them and keep running. To do that we need to check $medieclass using is_array() whether it has null values or not.

For this, we need we will put $medieclass in is_array()

Here you see we have is_array() to check if the $medieclass is an array or not. If it's not an array then, we will skip the condition so that, we don't need to execute in_array().

Thus we avoid the crush.


Add Reviews