php 는 배열 의 특정 값 의 모든 아래 표 시 를 되 돌려 줍 니 다.
2467 단어 php
첫 번 째 아래 표 array_search
다음 array_keys 배합 선택 가능 한 매개 변수 searchvalue 완료
eg:
function showIndex($source_arr, $sum)
{
$index_list = [];
$pass_index_list = [];
foreach ($source_arr as $index => $value) {
// filter repeat index
if (in_array($value, $pass_index_list)) {
continue;
}
// search another index
$diff = $sum - $value;
$ano_index = array_keys($source_arr, $diff);
if (!$ano_index) {
continue;
}
foreach ($ano_index as $choose_index) {
$index_list[] = [$index,$choose_index];
}
// set repeat index
$pass_index_list[] = $diff;
}
return $index_list;
}
// run function
$source_arr = [49, 1, 2, 3, 50, 50,49,49, 51];
//$source_arr = [49, 1, 2, 3, 50, 51];
$sum = 99;
print_r(showIndex($source_arr, $sum));
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Laravel - 변환된 유효성 검사 규칙으로 API 요청 제공동적 콘텐츠를 위해 API를 통해 Laravel CMS에 연결하는 모바일 앱(또는 웹사이트) 구축을 고려하십시오. 이제 앱은 CMS에서 번역된 콘텐츠를 받을 것으로 예상되는 다국어 앱이 될 수 있습니다. 일반적으로 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.