Clarkeez Posted August 10, 2011 Share Posted August 10, 2011 Hey.. Weird problem I'm trying to use information in an array inside a function, but when I call it, the information is not there. Ill show you <?php $c['guild'] = array('region' => 'eu', 'realm' => 'kazzak', 'name' => 'almost imba'); function get_guild_api_url() { $out = 'http://'.$c['guild']['region'].'.battle.net/api/wow/guild/'.$c['guild']['realm'].'/'.$c['guild']['name'].''; return $out; } echo get_guild_api_url(); // it shows http://.battle.net/api/wow/guild// // as you can see nothing from the array is there ?> Any ideas? Link to comment https://forums.phpfreaks.com/topic/244456-random-variable-problem/ Share on other sites More sharing options...
requinix Posted August 10, 2011 Share Posted August 10, 2011 Just because you defined $c outside the function does not mean it is available inside the function. Since your function only needs the region, realm, and name, pass those three bits of information as arguments to get_guild_api_url(): function get_guild_api_url($region, $realm, $name) { Link to comment https://forums.phpfreaks.com/topic/244456-random-variable-problem/#findComment-1255612 Share on other sites More sharing options...
Clarkeez Posted August 10, 2011 Author Share Posted August 10, 2011 Ohh they have to be arguments! Ok mate thanks, I thought function could access outside variables.. ty! Link to comment https://forums.phpfreaks.com/topic/244456-random-variable-problem/#findComment-1255617 Share on other sites More sharing options...
requinix Posted August 11, 2011 Share Posted August 11, 2011 Ok mate thanks, I thought function could access outside variables.. Nope. It's one of the things PHP does differently from damn near the rest of the programming world. Link to comment https://forums.phpfreaks.com/topic/244456-random-variable-problem/#findComment-1255635 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.