stubarny Posted June 23, 2012 Share Posted June 23, 2012 Hi All, I have the code below which returns "<br>line 82, dalmonfishing<br>". Please could you explain why it doesn't return "<br>line 82, salmonfishing<br>"? (i.e. why is the s getting replaced with a d?) $_SESSION[process_sign_up][sign_up_email]="salmonfishing"; $_SESSION[process_sign_up][sign_up_email][test_result_detail]="duplicate"; echo "<br>line 82, " . $_SESSION[process_sign_up][sign_up_email] . "<br>"; Thanks, Stu Quote Link to comment https://forums.phpfreaks.com/topic/264660-multi-dimensional-array/ Share on other sites More sharing options...
Pikachu2000 Posted June 23, 2012 Share Posted June 23, 2012 You're attempting to treat the string value in the ['sign_up_email'] index as an array and push the value "duplicate" onto it. You can't add array elements to a string value. Also, you should have error_reporting set to -1 and display_error set to On while developing. All of your array indices are throwing undefined constant notices because they aren't quoted. Quote Link to comment https://forums.phpfreaks.com/topic/264660-multi-dimensional-array/#findComment-1356416 Share on other sites More sharing options...
stubarny Posted June 23, 2012 Author Share Posted June 23, 2012 Thanks Pikachu2000 :-) Regarding the quotations in the indices please could you tell me what are the practical implications of not using quotations are? I noticed that my arrays worked fine without the quotations so I stopped using them to improve the readabililty of my code. Thanks, Stu Quote Link to comment https://forums.phpfreaks.com/topic/264660-multi-dimensional-array/#findComment-1356418 Share on other sites More sharing options...
Pikachu2000 Posted June 23, 2012 Share Posted June 23, 2012 Without the quotes, php first looks for a defined constant matching a string value in the array index. It eats processor cycles in doing so and when the constant isn't found, eats more processor cycles generating the notice. Suppressing the errors doesn't change that. Run this code and see how the output it generates is different from what you may expect: define('bob', 'jones'); $names = array('bob' => 'smith', 'jones' => 'richard'); echo $names[bob]; echo "<br>"; echo $names['bob']; Quote Link to comment https://forums.phpfreaks.com/topic/264660-multi-dimensional-array/#findComment-1356422 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.