1

Hi guys I am using the array_Push function and I am wondering if there's any way for the array_push function to return

                array_push($result, array('order_id' => $row[0],
                                  'type'  => $row[2],
                                  'description' => nl2br($row[3]),
                                  'amount' => $row[4],
                                  ));

and with the json_encode i get

   "result":[{"order_id":"67","type":"HEADER","description":"Coca Cola","amount":null},{"order_id":"72","type":"TEXT","description":"French Fries","amount":null}

this is output in a table as

    $.each(data.result, function(){
        $("tbody").append("<tr id='order_"+this['order_id']+"'><td>"+this['type']+"</td><td></td><td>"+this['description']+" </td><td>"+this['amount']+"</td><br>");

So i was wondering if there is a way for the NULL values to be returned as blanks instead? IF so, where can I do this?

2
  • 2
    "Blanks" is not a thing in PHP, or any language I'm aware of for that matter. Commented Apr 8, 2014 at 17:32
  • 1
    You might want to fix the problem at the source. Do you really need / want NULL values in your table instead of empty strings for strings and a 0 for amounts? Commented Apr 8, 2014 at 17:35

2 Answers 2

4

Just do

'amount' => (is_null($row[4]) ? '' : $row[4])
Sign up to request clarification or add additional context in comments.

1 Comment

I'd use === null, but that's just me. The fewer parenthesis the better. ;) +1
1
foreach($row as &$value){   
    $value = $value === null ? '' : $value;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.