I loop through a big array and got a small array of ids
foreach ($cats as $cat)
$cat_ids[] = $cat->term_id;
sometimes the $cat_ids has only one element. Array ( [0] => 123 )
When I check if a random id is in this $cat_ids array, if( in_array( $int,$cats_ids ))
I may get error message of $cat_ids “in_array() expects parameter 2 to be array,…”
How can I check if $int is in $cat_ids properly?
It doesn’t matter if the array has zero values or more. It just needs to be an array. So you have some error with the variable. If it is not an array, you could always typecast it into an array using
(array)$cats_ids