Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

global array

Status
Not open for further replies.

flea333

Technical User
Sep 4, 2003
47
US
I have a function and I am defining an array inside it. However I declare the array outside the function so I thought it would be global, however outside the function I can't read the array.

I define it as:
$imagearray = array();

Then I define each component inside the function.
 
Did you declare the array as global inside your function? I would think that may be a possible problem.

global $imagearray;

should be near the top of your function.

 
This is one way of doing it:

Code:
<?php

function addThis($data) {
  $GLOBALS["myArray"][].= $data;
}

addThis("Hello");
addThis("A short message");
addThis("Goodbye");

echo count($myArray)." records has been added.<HR>";

foreach($myArray as $value)
  echo $value."<BR>";

?>


Jakob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top