2014-11-04 117 views
0

我需要檢查在我的數組中是否有不同於0的值(對於這種特殊情況)。數組也可以從1個元素到m個元素。或多或少像in_array的倒數。檢查一個數組是否具有不同於零的值

我的陣列的形式爲:(這些是隨機數,可以改變位置)

array('0', '1', '1', '3', '1', '5', '0' '2' /*...*/); 

有沒有這樣的功能,或做我需要做一個循環來運行整個陣列,並檢查各指數?

+0

你需要返回的值,或你知道需要檢查是否存在0以外的值? – Flosculus 2014-11-04 15:29:00

+3

可能的重複:http://stackoverflow.com/questions/9266757/php-find-out-if-array-contains-values-of-0over-0 – LorDex 2014-11-04 15:29:30

+1

if(count(array_filter($ myArray))> 0) {...}' – 2014-11-04 15:29:43

回答

2

可以使用功能max()從數組返回的最高值

if (max($myArray) > 0) { #do ur thing } 
+0

是的,會做。乾杯。 – Comum 2014-11-04 15:37:23

+0

謝謝.... :) .. – 2014-11-04 15:41:01

+2

剽竊!!!!! – Flosculus 2014-11-04 15:44:03

2

很多辦法做到這一點,這裏是一個:

function has_other_than_zero($array) { 
    return intval(implode($array, '')); 
} 
相關問題