私は2つのphpファイルを持っています。最初のファイルには 2 番目のファイルが含まれます。これはすべて機能します。ただし、配列を持っている 2 番目のファイルを int します。
//set required items
$reqSettings = array(
"apiUser" => true,
"apiPass" => true,
"apiKey" => true,
);
最初のファイルで呼び出された関数で、この配列をループしたいのですが、関数によって認識されません:
function apiSettingsOk($arr) {
global $reqSettings;
$length = count($reqSettings);
echo $length; //returns 0 and not 3
}
ご覧のとおり、「グローバル」を使用してみましたが、これも機能しません。この問題を解決するのを手伝ってもらえますか?
完全を期すために、ここに 2 つのファイルを示します ;)
ファイル 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;
}
?>