1

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.

2
  • 3
    Post some code, or at least a plain-text array structure. It's difficult to tell what you're asking. Commented May 25, 2012 at 3:25
  • Apologies. The problem I have is testing if the declaration is false, such that e.g. if(!($array["index"] = $value)) { //output error } or by if($array["index"] != $value) { //output error } Commented May 25, 2012 at 3:31

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

7 Comments

The key is already set though (e.g. array_push($array["key"], $value) should return true)
Thanks, but it still doesn't solve the problem -- PHP is still outputting an undefined response.
Hmm, suppose I append an associative value by the following means: if($array["index"] != $value) { print "Cannot append value"; } Will that force the value to be false?
That doesn't append anything, it's just testing the value of it.
I want to test if the assignment is true, i.e. if it succeeded.
|
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.