Sunday, November 12, 2017

array_key_exists(): The first argument should be either a string or an integer


array_key_exists(): The first argument should be either a string or an integer In Php when you get this error , that means you are dealing with an Array , and your code trying to get some keys out of this Array, but instead of passing a single parameter (string or an integer) to the function that do the job,you are passing something else.
Example :

$arr = [
'color' => 'Red',
'price' => '50'
]

Now, when you try to check if the color is red you are going to use the code :

if($arr['color'] === 'Red') echo "Red";

and that's ok and no error will be thrown, but the following code:

if($arr['color','price'] === 'Red') echo "Red";

will throw an Error Exception.as the error given above.

No comments:

Post a Comment