in_array check returns false for existing key?

user17189691

dd($result); ian array like below.But it returns false for the check in_array('resourceId',$result).Can someone tell me why it behaves so?

array:1 [
  "resourceId" => "Etkl6g-zSB7EpP-Da1zN619mWbo8UZGl1R467hyNsftAO3as_gtcNJeFMgY63hjE2tfT_Wbt-PQ8FB9cmhV6mPPMCmvbDQMSFRQuif2zhlz8kTdJhUNUX1Vp6aXSLQ4LOPWZ8-ncRXILvjnrbJmjFiCx9Z4hi_eNIC-MF7uQxvgEZX_OYfwMgKiba5gSXYSnaubB4qqo7hKJBbR-TfdAeGW0S22sP3pLI99aX55gLU5DS8eC_Gb6Gfz-99rDTjvlZxfpfaCXU6C0VHfMl3vcTg5UqmVU9agtas3yHOILu7qBDMdTfVK8J"
]
Nigel Ren

in_array() looks for a value and not the key.

Use something like

if (isset($result['resourceId')))

which checks if there is a key with that name.

There is also some useful info on What's quicker and better to determine if an array key exists in PHP? about various aspects of checking if a key exists.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related