Taking a string of period separated properties and converting it to a json object in php.
I'm fairly sure I'm missing something blindingly obvious here but here it goes.

I am working on updating a search function in an application which was running a loop and doing a very large number of sql queries to get object / table relations to one large query that returns everything. However the only way I could think to return relations was period separated, what I am now wanting to do is take the flat array of keys and values and convert it into an associative array to then be jsonified with json_encode.

For example what I have is this...

<code>
array(
     "ID"=>10,
     "CompanyName"=>"Some Company",
     "CompanyStatusID"=>2,
     "CompanyStatus.Status"=>"Active",
     "addressID"=>134,
     "address.postcode"=>"XXX XXXX",
     "address.street"=>"Some Street"
);
</code>

And what I want to turn it into is this...

<code>
array(
     "ID"=>10,
     "CompanyName"=>"Some Company",
     "CompanyStatusID"=>2,
     "CompanyStatus"=>array(
          "Status"=>"Active"
     ),
     "addressID"=>134,
     "address"=>array(
          "postcode"=>"XXX XXXX",
          "street"=>"Some Street"
     )
);
</code>

Now I'm sure this should be a fairly simple recursive loop but for the life of me this morning I can't figure it out.

Any help is greatly appreciated.

Regards

Graham.
Taking a string of period separated properties and converting it to a json object in php.
===

I'm fairly sure I'm missing something blindingly obvious here but here it goes.

I am working on updating a search function in an application which was running a loop and doing a very large number of sql queries to get object / table relations to one large query that returns everything. However the only way I could think to return relations was period separated, what I am now wanting to do is take the flat array of keys and values and convert it into an associative array to then be jsonified with json_encode.

For example what I have is this...

<code>
array(
     "ID"=>10,
     "CompanyName"=>"Some Company",
     "CompanyStatusID"=>2,
     "CompanyStatus.Status"=>"Active",
     "addressID"=>134,
     "address.postcode"=>"XXX XXXX",
     "address.street"=>"Some Street"
);
</code>

And what I want to turn it into is this...

<code>
array(
     "ID"=>10,
     "CompanyName"=>"Some Company",
     "CompanyStatusID"=>2,
     "CompanyStatus"=>array(
          "Status"=>"Active"
     ),
     "addressID"=>134,
     "address"=>array(
          "postcode"=>"XXX XXXX",
          "street"=>"Some Street"
     )
);
</code>

Now I'm sure this should be a fairly simple recursive loop but for the life of me this morning I can't figure it out.

Any help is greatly appreciated.

Regards

Graham.