1

I am facing this error in our staging environment Exception: Warning: array_key_exists() expects parameter 2 to be array, null given

here added my code

$hash = array();
$hash['0'] = 'test';
$array_out = array();
foreach($data as $i_tem) {
    $hash_key = $i_tem[2];

 if(!array_key_exists($hash_key, $hash)) {
        $hash[$hash_key] = sizeof($array_out);
        array_push($array_out, array(
            'id' => $i_tem[2],
            'title' => $i_tem[4],
            'count' => 0,
        ));
    }
 $array_out[$hash[$hash_key]]['count'] += 1;
}
  • when do you get this error ? – Rahul Makwana Sep 21 '18 at 10:03
  • when i execute in array than this error facing – Rv Singh Sep 21 '18 at 10:04
  • Please provide some code , the error is clear here that array_key_exists() function expect second parameter to be array but its getting null value . We can guide you better after seeing some code that you have implemented. – Rahul Makwana Sep 21 '18 at 10:06
  • I have put my code please check it – Rv Singh Sep 21 '18 at 10:09
1

Please try with below code :

if (is_array($hash) && array_key_exists($hash_key, $hash))
    {
       //...magic stuff here 
    }

hope its work for you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.