, Daha sonra önceki cevaplar sizin için çalışacaktır. Örneğinizin 8000 aralığındaki kimlikleri olduğu düşünüldüğünde, her bir kimliğin ideal olmayabileceğinden şüpheleniyorum.
//start with JSON stored as a string in $jsonStr variable
// pull sorted array from JSON
$sortedArray = json_decode($jsonStr, true);
$target = 8097; //this can be changed to any other ID you need to find
$targetPerson = findContentByIndex($sortedArray, $target, 0, count($sortedArray));
if ($targetPerson == -1) //no match was found
echo "No Match Found";
function findContentByIndex($sortedArray, $target, $low, $high) {
//this is basically a binary search
if ($high < low) return -1; //match not found
$mid = $low + (($high-$low)/2)
if ($sortedArray[$mid]['id'] > $target)
//search the first half of the remaining objects
return findContentByIndex($sortedArray, $target, $low, $mid - 1);
else if ($sortedArray[$mid]['id'] < $target)
//search the second half of the remaining objects
return findContentByIndex($sortedArray, $target, $mid + 1, $high);
else
//match found! return it!
return $sortedArray[$mid];
}
kaç peope-> id dizisi – Ibu
geçmesi için bir döngü oluşturabilirsiniz: Yani burada (ID sırasına göre sürece insanlar gibi) doğru bir bulgu önce çok az kişi inceleyeceğiz diğer bir yöntemdir insanlar temsil edilir? Yeterince küçükse, aşağıda sunulan arama döngülerinden biri iyi çalışabilir. Çok büyükse, başka bir şeye ihtiyacınız olabilir. –
Ayrıca, girişler her zaman artan sırayla mı? Eğer öyleyse, etrafında inşa edilmiş bir algoritma, her girişten döngülenmekten çok daha verimli bir şey üretebilir. –