1
我想檢查多維數組中的值是否與給定的百分比相同。將多維數組中的相應值和相同的百分比返回給定值。 (PHP)
例如,這是我的數組:
$shop = array(array(Title => "rose",
Price => 1.25,
Number => 15
),
array(Title => "daisy",
Price => 0.75,
Number => 25,
),
array(Title => "orchid",
Price => 1.15,
Number => 7
)
);
,如果一個給定的值(比如說「testorchid」)是55%相同的多維陣列中的值。返回多維數組中相應的值和相同的值。
所以在這種情況下。如果我與「testorchid」檢查,它返回「蘭花」和55.56 procent。 像similar_text有點():工作
我可以檢查是否給定值(針)是一樣的多維數組中值的函數:
function in_array_r($needle, $haystack, $strict = true) {
foreach ($haystack as $item) {
if (($strict ? $item === $needle : $item == $needle) || (is_array($item) && in_array_r($needle, $item, $strict))) {
return true;
}
}
return false;
}
但它只返回true時一個值是完全一樣的。不是多維數組中的相應值,而不是相同值的百分比。
我想說這樣的話:如果「orchidtest」與多維數組中的[「title」]大於等於60%,那麼給這個值賦予百分比。
非常感謝你! – user1386906
@ user1386906完全沒有問題,這是一個相當不錯的小挑戰:) – Dale