0

please help me figure out the error to find the value by key. As the value is printed when using a string but not a variable with the same value. Thanks in advance

Code:

print_r($ESSID_data);
print_r($ESSID_data['criticalboot']);
print_r($myssid);
print_r($ESSID_data[$myssid]);

output:

Array ( [criticalboot] => Array ( [0] => CCMP [1] => PSK ) ) 
Array ( [0] => CCMP [1] => PSK ) 
criticalboot 
Undefined index: criticalboot 
4
  • 2
    Instead of print_r use var_dump and check again. Commented Jun 27, 2014 at 8:19
  • 4
    How is $myssid declared? Maybe it contains a space. Commented Jun 27, 2014 at 8:26
  • 1
    I tested this by declaring $ESSID_data = array("criticalboot" => array("CCMP", "PSK")); and $myssid = "criticalboot"; and it works just fine. Commented Jun 27, 2014 at 8:29
  • Trailing whitespace...? Non-printing characters...? Commented Jun 27, 2014 at 8:40

1 Answer 1

1

Try to do trim() first before feeding it into the index. Like:

$myssid = trim($myssid);
print_r($ESSID_data[$myssid]);
Sign up to request clarification or add additional context in comments.

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.