ballhogjoni Posted April 18, 2011 Share Posted April 18, 2011 what am I doing wrong? I have an assoc array, but I can't seem to access it. $var = Array ( 'domain' => asdfasdf.com 'port' => 2082 'adminuser' => admin 'INST_password' => adsfasdf 'adminnickname' => admin 'adminemail' => [email protected] 'sitename' => Play Bingo Online Austrailia 'description' => How to play bingo online in Australia 'site_root_path' => /home/chris/public_html/ 'theme' => default 'anchor_one' => How to play bingo online in Australia 'anchor_two' => play bingo 'anchor_three' => bingo online ) if( empty($var['domain']) ) exit; the code exits everytime. What am I missing? Quote Link to comment https://forums.phpfreaks.com/topic/234056-cant-access-array-elements/ Share on other sites More sharing options...
drisate Posted April 18, 2011 Share Posted April 18, 2011 LOL ... How are we supose to tell you what your doing wrong if you don't show the code lol <?php echo $var['domain']; // asdfasdf.com ?> Quote Link to comment https://forums.phpfreaks.com/topic/234056-cant-access-array-elements/#findComment-1202974 Share on other sites More sharing options...
ballhogjoni Posted April 18, 2011 Author Share Posted April 18, 2011 Did you scroll to the bottom of the code snippet? Quote Link to comment https://forums.phpfreaks.com/topic/234056-cant-access-array-elements/#findComment-1202977 Share on other sites More sharing options...
Muddy_Funster Posted April 18, 2011 Share Posted April 18, 2011 When declaring the contents of an array, you do not use the [] to surround the identifiers. Quote Link to comment https://forums.phpfreaks.com/topic/234056-cant-access-array-elements/#findComment-1202978 Share on other sites More sharing options...
ballhogjoni Posted April 18, 2011 Author Share Posted April 18, 2011 When declaring the contents of an array, you do not use the [] to surround the identifiers. ya sorry just copied and pasted the array I was outputting to the screen via print_r Quote Link to comment https://forums.phpfreaks.com/topic/234056-cant-access-array-elements/#findComment-1202983 Share on other sites More sharing options...
Muddy_Funster Posted April 18, 2011 Share Posted April 18, 2011 ok, and is that the same reason that the values are not wrapped in single quotes as well? Quote Link to comment https://forums.phpfreaks.com/topic/234056-cant-access-array-elements/#findComment-1203006 Share on other sites More sharing options...
kenrbnsn Posted April 18, 2011 Share Posted April 18, 2011 Why don't you post what's in your script, so we see what you're really trying to run. Ken Quote Link to comment https://forums.phpfreaks.com/topic/234056-cant-access-array-elements/#findComment-1203017 Share on other sites More sharing options...
drisate Posted April 18, 2011 Share Posted April 18, 2011 Did you scroll to the bottom of the code snippet? Yes but we need more of your code... Post the part where your creating the array and trying to use it Quote Link to comment https://forums.phpfreaks.com/topic/234056-cant-access-array-elements/#findComment-1203024 Share on other sites More sharing options...
ballhogjoni Posted April 18, 2011 Author Share Posted April 18, 2011 im sorry to post back, I forgot about this. I figured it out a while ago. The problem was how I was creating the array. I was using an html form to create the array. So I had something like: <input name="site[0]['domain']" /> <input name="site[1]['domain']" /> etc... So apparently this is wrong, I changed the html inputs to this: <input name="site[0][domain]" /> <input name="site[1][domain]" /> etc... notice no more single quotes around domain. This change fixed my problem. Quote Link to comment https://forums.phpfreaks.com/topic/234056-cant-access-array-elements/#findComment-1203177 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.