Reputation: 495
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
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
Reputation: 324640
I think you're looking for isset()
, for example if( isset($array['key'])) ...
Upvotes: 2