I have two php files. the first file will include the second one. This all works. However, int the second file I have an array:
//set required items
$reqSettings = array(
"apiUser" => true,
"apiPass" => true,
"apiKey" => true,
);
In a function called in the first file I want to loop through this array, however it is not recognized by the function:
function apiSettingsOk($arr) {
global $reqSettings;
$length = count($reqSettings);
echo $length; //returns 0 and not 3
}
As you can see I tried using 'global' but this doesn't work either. Can you help me out fixing this issue?
Here are the two files just for completeness sake ;)
file 1:
$apiArr = array();
if (isset($_POST['api-submit'])) {
$gateWay = $_POST['of-sms-gateway'];
$apiArr['apiUser'] = $_POST['api-user'];
$apiArr['apiPass'] = $_POST['api-passwd'];
$apiArr['apiKey'] = $_POST['api-key'];
//including the gateway file
include_once('of_sms_gateway_' . $gateWay . '.php');
if (apiSettingsOk() === true) {
echo "CORRECT";
}
}
?>
of_sms_gateway_test.php :
<?php
//set required items
$reqSettings = array(
"apiUser" => true,
"apiPass" => true,
"apiKey" => true,
);
function apiSettingsOk($arr) {
global $reqSettings;
$returnVar = true;
$length = count($reqSettings);
echo $length;
return $returnVar;
}
?>
apiSettingsOk($arr)need parameter$arr, where is that ?? if the function without parrameter, then look: codepad.org/IlC8qtdB