This is simple but I am trying to echo a value from function-1 inside function-2
function testing(){
$files1 = "dir";
}
function tested() {
testing();
echo "testing".$files1;
}
Any help on why its not working would be appreciated.
This is simple but I am trying to echo a value from function-1 inside function-2
function testing(){
$files1 = "dir";
}
function tested() {
testing();
echo "testing".$files1;
}
Any help on why its not working would be appreciated.
For this you have to return value from function
function testing(){
$files1 = "dir";
return $files1;
}
function tested() {
$files1 = testing();
echo "testing".$files1;
}
tested();
they function run but the second function doesn't understand the local variable from function one.
I would do the following
<?php
function testing(){
$files1 = "dir";
return $files1;
}
function tested() {
$files1 = testing();
echo "testing".$files1;
}
tested();
?>
or you could use the global variable.
<?php
function testing(){
$GLOBALS['files1'] = "dir";
// return $files1;
}
function tested() {
testing();
echo "testing ". $GLOBALS['files1'];
}
tested();
?>