PHP array set null value
<p>How can I set array value to <code>null</code> if no data exist? </p>

<p>Following is my array from PHP and I am json encoding - </p>

<pre><code>{  
   "title":"Impalz-Marketing",
   "type":"Business Details",
   "version":"1.0",
   "login":[  ],
   "business":{  
      "1":{  
         "details":{  },
         "messages":[  ],
         "offers":[  ],
         "events":[  ],
         "milestone":[  ],
         "products":[  ],
         "brand_exp":[  ],
         "reviews":[  ],
         "agg_reviews":{  }
      },
      "168":{  
         "details":{  },
         "messages":[  ],
         "products":[  ]
      }
   }
}
</code></pre>

<p>Number of rows are uneven in both business. How can I set data to null if no row exist?  </p>

<pre><code>$data = array(
        'title' =&gt; 'Impalz-Marketing',
        'type' =&gt; 'Business Details',
        'version' =&gt; '1.0',
        'login' =&gt; $login_array,
        'business' =&gt; $business_details_array
);
</code></pre>

<p>I've tried this:</p>

<pre><code>$business_details_array = array();
while($row = mysql_fetch_assoc($biz_list))
{
    $business_details_array[$row['id']]['details'] = $row;
}

    while($row = mysql_fetch_assoc($biz_milestone))
    {
        if(!empty($row['id'])){
            $temp= explode(',', $row['path']);
            if(count($temp) &gt; 1) {
                $row['path']= $temp;
            }
            $business_details_array[$row['business_id']]['milestone'][] = $row;
        }else{  
            $business_details_array[]['milestone'][] = null; // since no data exist their wont be any business_id
        }       
    }    
</code></pre>

<p>I want something like this - </p>

<pre><code>{  
   "title":"Impalz-Marketing",
   "type":"Business Details",
   "version":"1.0",
   "login":[  ],
   "business":{  
      "1":{  
         "details":{  },
         "messages":[  ],
         "offers":[  ],
         "events":[  ],
         "milestone":[  ],
         "products":[  ],
         "brand_exp":[  ],
         "reviews":[  ],
         "agg_reviews":{  }
      },
      "168":{  
         "details":{  },
         "messages":[  ],
         "offers": "null",
         "events": "null",
         "milestone": "null",
         "products":[  ],
         "brand_exp": "null",
         "reviews": "null",
         "agg_reviews": "null"
      }
   }
}
</code></pre>