MLBPlayer Posted December 31, 2009 Share Posted December 31, 2009 I am trying to make this work so I can use a global function for my Moderator List. $rofl = "test,lol"; $moderators = array($rofl); if (in_array(strtolower($_SESSION['user_name']), array_map('strtolower', $moderators))) { echo "You have access!"; }else{ echo "You do not have access" } I get the array from my $_SESSION username. But the above does not work, help? Quote Link to comment https://forums.phpfreaks.com/topic/186792-help-global-array/ Share on other sites More sharing options...
PFMaBiSmAd Posted December 31, 2009 Share Posted December 31, 2009 $rofl = "test,lol"; $moderators = array($rofl); The above code does not create an array that two entries. It creates an array that has one entry with the value "test,lol". If you want or need to start with a comma separated list, use explode to get it into an array. Quote Link to comment https://forums.phpfreaks.com/topic/186792-help-global-array/#findComment-986398 Share on other sites More sharing options...
MLBPlayer Posted December 31, 2009 Author Share Posted December 31, 2009 $rofl = "test,lol"; $moderators = array($rofl); The above code does not create an array that two entries. It creates an array that has one entry with the value "test,lol". If you want or need to start with a comma separated list, use explode to get it into an array. function moderators(){ $str = 'test,two,three,four'; explode(',', $str, 0); return $str; } and $moderators = array(moderators()); if (in_array(strtolower($_SESSION['user_name']), array_map('strtolower', $moderators))) { It's not working, Help me? Quote Link to comment https://forums.phpfreaks.com/topic/186792-help-global-array/#findComment-986400 Share on other sites More sharing options...
wildteen88 Posted December 31, 2009 Share Posted December 31, 2009 Remove array() from this line $moderators = array(moderators()); The moderators() function already returns an array. Quote Link to comment https://forums.phpfreaks.com/topic/186792-help-global-array/#findComment-986505 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.