如何在循环内迭代x的值?它不会迭代。谢谢你的帮助!
$x = 0;
foreach($searchResponse->searchResult->recordList as $customer => $value) {
$custInternalId = $value[$x]->internalId;
$request = new GetRequest();
$request->baseRef = new RecordRef();
$request->baseRef->internalId = $custInternalId;
$request->baseRef->type = "customer";
$getResponse = $service->get($request);
$cust = $getResponse->readResponse->record;
$x++;
}
答案 0 :(得分:1)
要调试它,请打印数据:
foreach($searchResponse->searchResult->recordList as $customer => $value) {
var_dump($customer);
var_dump($value);
break;/*single record printing//
}
在删除敏感数据后发布我们的问题调查信息
这就是for each
在PHP (see doc)中的工作原理:
foreach (array_expression as $key => $value) { /*statement*/ }
我的猜测是,您将了解如何从这些输出中获取客户的ID。发布他们的问题,我们会帮助您。
看起来您正在使用NetSuite的recordList,它应循环通过以获取记录和记录具有字段getter函数!
foreach ( $searchResponse->recordList as $record ){
$internalId = $record->getField("internalId");
}
根据NetSuite Doc:
,我猜你想要类似这样的东西foreach($searchResponse->searchResult->recordList as $customerKey => $customerData) {
$custInternalId = $customerData->getField("internalId");
$request = new GetRequest();
$request->baseRef = new RecordRef();
$request->baseRef->internalId = $custInternalId;
$request->baseRef->type = "customer";
$getResponse = $service->get($request);
$cust = $getResponse->readResponse->record;
}
答案 1 :(得分:0)
在循环之前和之外声明/初始化$x
:
$x = 0;
foreach($searchResponse->searchResult->recordList as $customer => $value) {
$custInternalId = $value[$x]->internalId;
$request = new GetRequest();
$request->baseRef = new RecordRef();
$request->baseRef->internalId = $custInternalId;
$request->baseRef->type = "customer";
$getResponse = $service->get($request);
$cust = $getResponse->readResponse->record;
$x++;
}
答案 2 :(得分:0)
在循环之前声明$ x:
$x = 0;
foreach($searchResponse->searchResult->recordList as $customer => $value) {
$custInternalId = $value[$x]->internalId;
$request = new GetRequest();
$request->baseRef = new RecordRef();
$request->baseRef->internalId = $custInternalId;
$request->baseRef->type = "customer";
$getResponse = $service->get($request);
$cust = $getResponse->readResponse->record;
echo $x;
$x++;
}
在循环中,您可以回显$ x以查看值
答案 3 :(得分:0)
您可以使用$customer
变量获取当前索引值,因为它是您的foreach循环的关键。