How To Make Array Variable Global In PHP Function

Mobile
feeds
Welcome Login | Register

How To Make Array Variable Global In PHP Function
  Forums Index
      » PHP Forums
        » » How to Make Array Variable Global In PHP Function



How To Make Array Variable Global In PHP Function
Post Description:
Post Tags: how, to, make, array, variable, global, in, php, function, free php support, php scripts, php questions, php answers, programming, codes, scripts
This Post Has Been Viewed 780 Times Since Sat Feb 23, 2008 11:14 pm Posted By hostman with 1 replies
How To Make Array Variable Global In PHP Function
today i had this problem, i had an array and i wanted to use it in a function, but when i tried to use it it wouldn't work. so if you are also having this issue, hopefully you can learn from my mistakes.

lets say for example i have this php code;



<?php
$array_string = array();
$array_string[0] = "zero";
$array_string[1] = "one";
$array_string[2] = "two";
$array_string[3] = "three";
function ($string){
echo $array_string[3];
?>


that wont work, so what you need to do is call the global array in your function, like this:
<?php
$array_string = array();
$array_string[0] = "zero";
$array_string[1] = "one";
$array_string[2] = "two";
$array_string[3] = "three";
function ($string){
global $array_string;
echo $array_string[3];
?>



Leave Your Comments






Share
URL:
You can use this HTML code to put it on your website to show your friends this wallpaper. Use this code on your profile like myspace, friendster, Facebook or others. Just Copy and Paste it in your HTML on your websites



Fourms BBCODE:
BBCODE is use on forums. You can put this code on all your BBCODE enabled forums like PhpBB, vBulletin® and others. Just Copy and Paste this code on your Posts and Replies on your forums





Comments and replies About How To Make Array Variable Global In PHP Function




:: 1 :: Reply #77503 Reply By yo On Sun Oct 26, 2008 6:59 am
cool comment dude , took me out of doubts , cheers.