현재 배열에서 데이터를 수집하고 API로 푸는 스크립트가 있습니다. 그러나 어떤 이유에서든 한 번에 하나 이상을 추가 할 수 없습니다.Foreach 루프 PHP 한 번 중지
$ 데이터 배열
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에 대한 첫 번째 배열이 아닌 두 번째를 밀어 버린다 -마다.
, 및 않습니다 당신은 실제로 저축을합니까? –
당신은'explode()'를 사용하여 정확하게 달성하고자하는 것은 무엇입니까? 두 내부 배열 모두'_client_ids'와'_parent_ids '는 모두 하나의 정수입니다. 쉼표로 구분 된 문자열이있는 경우가 있습니까? –