user6104636 user6104636 - 6 months ago 9
PHP Question

How to skip lines in php

I'm struggling in finding a way to correctly do this logic.

If (this thing is null)
Skip it
Don't skip it

I tried with if/else and while loops but each one will crash the program. I test something like this:

(inside a foreach)
if($value->getThing() == NULL) {
//I try to 'set' this thing
$value->setThing(0); //BUT IT Doesn't work because it's an associated object...
} else {

And tried this:

(inside foreach)
while ($value->getThing() != NULL) {
//Do Calculation...

Both just crash when it gets to the thing thats null. I know why but I can't figure out how to skip the null thing.

and if you can't tell, I'm a newbie. But I'm learning.

EDIT: The thing is null in the db.


Try this code :

foreach($values as $value){
    #do calculation