php - Insert values in an associative array but only if have value -


i've bucle:

foreach($jsonu $j) {         $jsonuid = $j->id;         $jsonuname = $j->name;         $jsonudescription = $j->description;         $jsonudate = $j->date;         $jsonustatus = $j->status;         $jsonupicture = $j->picture;          $jsonuncompleted[] = array('id'=> $jsonuid, 'name'=> $jsonuname, 'description' => $jsonudescription, 'date' => $jsonudate, 'status' => $jsonustatus, 'picture' =>$jsonupicture); }   

i need insert key in array if have value. example, $jsonupictore not has value , in case don't need write key.

some help?

you use array_filter function or without parameter:

http://www.php.net/manual/en/function.array-filter.php

example:

$jsonuncompleted[] = array_filter( array(   'id'=> $jsonuid, 'name'=> $jsonuname, 'description' => $jsonudescription,   'date' => $jsonudate, 'status' => $jsonustatus, 'picture' =>$jsonupicture )); 

Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -