Re: Simple @#%@#% array/function not working....

From: Date: Sun, 11 May 2003 14:42:14 +0000
Subject: Re: Simple @#%@#% array/function not working....
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-147207@lists.php.net to get a copy of this message
On 05/11/2003 9:13 AM, Ryan A (ryan@jumac.com) wrote: > I have an array and its working fine, but when i try to call a function that > checks if the array isset i dont get the required output. > Heres the code below: > > if (is_array($id)) { print "<pre>\$id = "; print_r($id); print > "</pre>\n"; } //working fine > $result = count ($id); //working fine > print($result); //working fine > > function one() > { > if(isset($id[0])) > return("test=".$id[0]); > } > echo "<h1>testing".one()."</h1>"; //HERES the problem, this is > only > printing "testing" instaed of "testing(array value)" As written, one() doesn't know about $id. Either pass $id to one(): function one($id) { if(isset($id[0])) return("test=".$id[0]); } echo "<h1>testing".one($id)."</h1>"; Or use global: function one() { global $id; if(isset($id[0])) return("test=".$id[0]); } Pablo

« previous php.general (#147207) next »