What can i do to fix Undefined array key 0 without adding @ to suppres the error

215 Views Asked by At
  • Since upgrade to php 8.1 i am having a Undefined array key 0 in error log. The line that shows the error is: if(osc_subdomain_type() == 'category' && $cat[0]['s_slug'] != osc_subdomain_slug() || osc_subdomain_type() != 'category') { $category = $cat[0];

By putting the @ sign the error is suppressed but not solved.... How can i fix this? All help appreciated.

1

There are 1 best solutions below

0
On

There is not much diff between using @ and different approach, however if you want to be 100% perfect, use:

if(osc_subdomain_type() == 'category' && isset($cat[0]) && $cat[0]['s_slug'] != osc_subdomain_slug() || osc_subdomain_type() != 'category') { 

$category = isset($cat[0]) ? $cat[0] : array(); }