문제

My PL/SQL procedure returns a cursor. It always returns data. I fetch (oci_fetch_assoc) it and save it in an array. If results were found the keys of the array will be strings. If the cursor didn't find data, it will return value 0, thus the key of the array will be numeric.

while($data = oci_fetch_assoc($cursor)){
    if(!isset($data[0])){
       ...
    }
...
...
}

What's the best way to check that the array is not just 0, but contains data?

Thanks

도움이 되었습니까?

해결책

Here is my solution:

if($data != array(0 => "0")){

and it works

다른 팁

if(!empty($data[0])) { ... }

oci_fetch_assoc returns an associated array, that is the column names are indexes in the array.

try one of these:

($data['firstColumn'] === 0)
(reset($data) === 0)

where 'firstColumn' is the actual name of the first column

You can use the '===' to see if $data[0] equals 0. Like:

if($data[0]===0) {
   // It really is the number 0
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top