只要做到這一點是這樣的:
include 'soapproxy.php';
$proxy = SoapProxy::login("astar", "Astar2012", "48");
$xmlusers = $proxy->getUsersInGroup("vehicles", 0);
foreach($xmlusers->user as $user) {
if($user->id > 1 {
$user = $user->id; // or try $_GET['user'] = $_REQUEST['user'] = $user->id; if the included script MUST have the data inside $_GET or $_REQUEST.
include 'send_data_to_db.php';
}
}
包括會乾脆把文件中的內容,並解析它,彷彿它只是當前的文件中。不能將參數添加到包含調用
但是,正如Rath所說,真正的最佳解決方案是編輯send_data_to_db.php,並將其內容作爲一個函數,它將$ user用作參數。然後,你會做這樣的事情:
include 'soapproxy.php';
include 'send_data_to_db.php'; // just include it once
$proxy = SoapProxy::login("astar", "Astar2012", "48");
$xmlusers = $proxy->getUsersInGroup("vehicles", 0);
foreach($xmlusers->user as $user) {
if($user->id > 1 {
the_function_in_send_data_to_db.php($user->id); // call the function you created in the file multiple times
}
}
爲什麼不創建一個發送數據和召喚功能的類? 我不知道爲什麼,但我不喜歡在循環中包含文件的想法。 –
@OfirBaruch在許多層面上這是錯誤的... – TheHippo