- Forums
- PHP
- How To Make An Array Variable Global In PHP Functions
This Page Contains information about How To Make An Array Variable Global In PHP Functions By wallpaperama in category PHP with 14 Replies. [1098], Last Updated: Sat May 18, 2024
wallpaperama
Sat Feb 23, 2008
14 Comments
13038 Visits
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];
?>