目前我有一個腳本,將從數組中收集數據並將其推送到API,但由於某種原因,我不能讓它添加更多,然後一次。foreach循環PHP一旦停止
$ data數組
array
(
[0] => Array
(
[_id] => 0
[_source] => App
[_source_id] => 790006230e91dd6279a42a814bf5965a.jpg
[_client_ids] => 2
[_parent_ids] => 0
[_image] => blank.jpg
[_title] => test1
[_body] => test1
)
[1] => Array
(
[_id] => 1
[_source] => App
[_source_id] => b3a5a6df0cf1dfc30882b20f8a493092.jpg
[_client_ids] => 2
[_parent_ids] => 0
[_image] => blank.jpg
[_title] => test2
[_body] => test2
)
)
PHP
public function save($data) {
$submissionManager = new SubmissionManager($this->container);
$returndata = array();
foreach($data as $entry)
{
$this->mustBeGranted('PERM_SUBMISSION_CREATE');
$saved = array();
$client_ids = explode(',', $entry['_client_ids']);
$parent_ids = explode(',', $entry['_parent_ids']);
$length = count($client_ids);
for($i = 0; $i < $length; $i++){
$input = array_merge($entry, array(
'client_id' => isset($client_ids[$i]) ? $client_ids[$i] : 0,
'parent_id' => isset($parent_ids[$i]) ? $parent_ids[$i] : 0,
'_source_id' => $entry['_source_id']
));
$saved[] = $submissionManager->createSubmission($input);
}
$returndata[ $entry['_id']] = $saved;
}
}
基本上只會推第一個數組的API,而不是第二個,即使我已經添加了對-每。
是什麼'returndata'看起來像$,以及何時你實際上做了儲蓄? –
你打算通過使用'explode()'來完成什麼?在兩個內部數組中,'_client_ids'和'_parent_ids'都是單個整數。有些情況下,這些將是一個逗號分隔的字符串? –