这样做:
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';
}
}
Include 将简单地获取文件内容并解析它,就好像它只是在当前文件中一样。您不能将参数添加到包含调用
但正如 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
}
}