acctman Posted May 8, 2009 Share Posted May 8, 2009 can someone assist me with the code below? Unexpected T_as error the countries.php file $countries['US'] = array(name => 'United States'); $countries['AF'] = array(name => 'Afghanistan'); code.. if ($en['mm_country'] != US || CA) { global $countries; include 'modules/members/countries.php'; $countries as $key => $value; $key = $en['mm_country']; $en['mm_coname'] = htmlentities($value['name'],ENT_QUOTES); echo $en['mm_coname']; } Quote Link to comment Share on other sites More sharing options...
AmandaF Posted May 8, 2009 Share Posted May 8, 2009 Are you trying to do a foreach loop? I don't think "as $key => $value" works outside of the context of a foreach loop. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 8, 2009 Share Posted May 8, 2009 Put quotes around name. $countries['US'] = array('name' => 'United States'); $countries['AF'] = array('name' => 'Afghanistan'); Quote Link to comment Share on other sites More sharing options...
acctman Posted May 8, 2009 Author Share Posted May 8, 2009 Are you trying to do a foreach loop? I don't think "as $key => $value" works outside of the context of a foreach loop. no not doing a foreach just need to grab the country name for $key Quote Link to comment Share on other sites More sharing options...
acctman Posted May 8, 2009 Author Share Posted May 8, 2009 Put quotes around name. $countries['US'] = array('name' => 'United States'); $countries['AF'] = array('name' => 'Afghanistan'); this is already formated in a file, and works fine without the quotes when used elsewhere on the site. Quote Link to comment Share on other sites More sharing options...
Mchl Posted May 8, 2009 Share Posted May 8, 2009 Then use normal array access $key = "US"; $country = $countries[$key]; Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 8, 2009 Share Posted May 8, 2009 if ($en['mm_country'] != US || CA) { Are US and CA strings or constants? Quote Link to comment Share on other sites More sharing options...
Mchl Posted May 8, 2009 Share Posted May 8, 2009 Doesn't matter. If there's no constant defined, PHP will assume string (and throw a Notice) Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 8, 2009 Share Posted May 8, 2009 Doesn't matter. If there's no constant defined, PHP will assume string (and throw a Notice) I didn't know that. Thanks! One more thing, what does this line do? $countries as $key => $value; Quote Link to comment Share on other sites More sharing options...
Mchl Posted May 8, 2009 Share Posted May 8, 2009 Throws an error obviously Quote Link to comment Share on other sites More sharing options...
thebadbad Posted May 8, 2009 Share Posted May 8, 2009 if ($en['mm_country'] != US || CA) { Means: if ($en['mm_country'] != US) is true or if (CA) is true. I.e. it will always be true. I guess you're looking for if (in_array($en['mm_country'], array(US, CA))) { Quote Link to comment Share on other sites More sharing options...
acctman Posted May 8, 2009 Author Share Posted May 8, 2009 Then use normal array access $key = "US"; $country = $countries[$key]; when i do that the result is just Array. the code needs to be something like this, but i'm not sure how to code it correctly. if ($en['mm_country'] != US) || ($en['mm_country'] != CA) { global $countries; include 'modules/members/countries.php'; $key = $en['mm_country']; $country = $countries(htmlentities($key['name'],ENT_QUOTES)); echo $country; } Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 8, 2009 Share Posted May 8, 2009 What does "code it correctly" mean? You haven't told us what you want. Quote Link to comment Share on other sites More sharing options...
acctman Posted May 8, 2009 Author Share Posted May 8, 2009 What does "code it correctly" mean? You haven't told us what you want. oh sorry i thought i did, i want to connect to countries.php and grab the country name. $en['mm_country'] holds the $key abbervation of the country. so if AF is supplied then when I echo $country the return value should be Afghanistan. also when grabbing the country name htmlentities needs to be used to strip the quotes $countries['US'] = array(name => 'United States'); $countries['AF'] = array(name => 'Afghanistan'); Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 8, 2009 Share Posted May 8, 2009 $countries(htmlentities($key['name'],ENT_QUOTES)); ^ $countries is an array. Use brackets, not parentheses. $country = htmlentities($countries[$key['name']], ENT_QUOTES); Like that? Quote Link to comment Share on other sites More sharing options...
Mchl Posted May 8, 2009 Share Posted May 8, 2009 More like $country = htmlentities($countries[$key]['name'], ENT_QUOTES); Quote Link to comment Share on other sites More sharing options...
acctman Posted May 8, 2009 Author Share Posted May 8, 2009 $countries(htmlentities($key['name'],ENT_QUOTES)); ^ $countries is an array. Use brackets, not parentheses. $country = htmlentities($countries[$key['name']], ENT_QUOTES); Like that? nothing was returned, no error. Quote Link to comment Share on other sites More sharing options...
acctman Posted May 8, 2009 Author Share Posted May 8, 2009 More like $country = htmlentities($countries[$key]['name'], ENT_QUOTES); that worked thanks. Quote Link to comment 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.