
December 21st, 2012, 01:52 PM
|
|
Contributing User
|
|
Join Date: Apr 2003
Posts: 321
  
Time spent in forums: 1 Day 21 h 37 m 39 sec
Reputation Power: 12
|
|
|
Vaiables between two functions
Is there a way to use a variable like a global variable between two functions?
PHP Code:
function get_folders () {
if ($handle = opendir('products')) {
$blacklist = array('.','..','products', 'index.php');
while (false !== ($file = readdir($handle))) {
if (!in_array($file, $blacklist)) {
echo '<a href=/products_list.php?folder=' . $file . '&'. 'pdf=' . '/>'. strtoupper($file) . '</a>'. '<br/>';
}
}
closedir($handle);
}
}
function get_products() {
//if ($handle = opendir('products/category1/product1')) { <<Remove this
if ($handle = opendir($file)) { <<try this
$blacklist = array('.','..','index.php');
while (false !== ($product = readdir($handle))) {
if (!in_array($product, $blacklist)) {
echo '<a href=/products_list2.php?folder=' . $product . '&'. 'pdf=' . '/>'. strtoupper($product) . '</a>'. '<br/>';
}
}
closedir($handle);
}
}
I was trying something like this but get a message of bool(false) outside of the function I have :
global $file;
PHP Code:
if ($handle= opendir($GLOBALS['file']))
Last edited by mallen : December 21st, 2012 at 02:03 PM.
|