vote up 0 vote down star

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

flag
i'm not sure if i'm reading the question right, isset() checks for if your array[0] has a value attached to it :S – Rob Apr 8 at 14:41
sorry... my procedure always returns a cursor. When I open my first cursor I collect data. After this I check if any rows were found. If there aren't any, I'll open the cursor with a different Select statement, which always returns 0. So, in PHP I will always get an array with value in it. The goal of my condition is to find out if the array has not just 0 as a value $array[0] = 0). – Kel Apr 8 at 14:55

4 Answers

vote up 1 vote down check

Here is my solution:

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

and it works

link|flag
vote up 0 vote down
if(!empty($data[0])) { ... }
link|flag
sorry... my procedure always returns a cursor. When I open my first cursor I collect data. After this I check if any rows were found. If there aren't any, I'll open the cursor with a different Select statement, which always returns 0. So, in PHP I will always get an array with value in it. The goal of my condition is to find out if the array has not just 0 as a value $array[0] = 0). – Kel Apr 8 at 14:55
vote up 0 vote down

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

link|flag
vote up 0 vote down

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

if($data[0]===0) {
   // It really is the number 0
}
link|flag
sorry... my procedure always returns a cursor. When I open my first cursor I collect data. After this I check if any rows were found. If there aren't any, I'll open the cursor with a different Select statement, which always returns 0. So, in PHP I will always get an array with value in it. The goal of my condition is to find out if the array has not just 0 as a value $array[0] = 0). – Kel Apr 8 at 14:54
OK. Updated my answer. – zaf Apr 8 at 15:09

Your Answer

Get an OpenID
or
never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.