user784446
user784446

Reputation: 495

PHP associative array index undefined

Without looping a set of array keys acquired via array_keys($array), how else can I select the key of an array such that $array["key"] where "key" associates to a second subsequent array -- PHP otherwise outputs a notice stating that "key" is undefined.

Any help is sincerely appreciated.

Upvotes: 1

Views: 6374

Answers (2)

JeffK
JeffK

Reputation: 128

isset() works for variables, but the error your likely getting is for an undefined key/index. You'll want to try array_key_exists() before trying to use the key (and based on the results, either use or create the key).

http://www.php.net/manual/en/function.array-key-exists.php

Upvotes: 0

Niet the Dark Absol
Niet the Dark Absol

Reputation: 324640

I think you're looking for isset(), for example if( isset($array['key'])) ...

Upvotes: 2

Related Questions