vendredi 27 octobre 2017

isset() Vs. array_key_exists

Description

I made a call to an API, and I will get back an array, but there is a certain array key that always include as part of the reponse. The array key data


Attempt

Ex. $reponse = GET::API('/api/object/id'); 

I had these 2 in mind for my check

if (isset($response['data'])){
    ...
}

OR

if (array_key_exists('data', $response)) {
    ...
}

isset() Vs. array_key_exists

Which one is safe, and better to use and why ?


Questions

I'm open to any suggestions at this moment.

Any hints/suggestions / helps on this be will be much appreciated!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire