poe Posted March 11, 2007 Share Posted March 11, 2007 i have this function function showImg($filename) { if($filename != "") { $jpg = $filename; $messageAry['title'] = "woohoo, we have an image"; } else { $jpg = "default.jpg"; $messageAry['title'] = "no image found"; } return $jpg; } // end function $thepic = "superstar.jpg"; echo "<img src='".showImg($thepic)."'>"; but when i try to print the $messageAry for later use it doesnt show. print_r($messageAry); Link to comment https://forums.phpfreaks.com/topic/42185-array-in-a-function/ Share on other sites More sharing options...
jeremywesselman Posted March 11, 2007 Share Posted March 11, 2007 You need to declare the $messageAry global inside your function to access it outside of your function. function showImg($filename) { global $messageAry; if($filename != "") { $jpg = $filename; $messageAry['title'] = "woohoo, we have an image"; } else { $jpg = "default.jpg"; $messageAry['title'] = "no image found"; } return $jpg; } // end function Jeremy Link to comment https://forums.phpfreaks.com/topic/42185-array-in-a-function/#findComment-204664 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.