Jump to content

Obtain PHP array definition script based on JSON


Go to solution Solved by requinix,

Recommended Posts

I was in process of typing the PHP script such as $arr=['a'=>[],'b'=>['c'=>123]]; necessary to create an array which is based on a fairly large JSON object.  To save me some time, I used print_r(json_decode($myObj,true)); and it helped a little, but not much.  I will just keep plugging along, but I find myself doing this every now and then, and it would be nice to somehow generate the script.automatically.  Are any tricks available?  Thanks

I really have no idea what you are asking. Are you creating the array or are you retrieving the array from some source?

 

You state

 

 

create an array which is based on a fairly large JSON object.

 

So, do you have a specific object with a predetermined format that you must create data for? Depending on the complexity of that data structure, how often I need to create a new data set, etc. I would take different approaches. E.g. I might have a pre-filled array with some default values or placeholders, I might use an Excel document where I have inputs for the various values and some code that puts them into the pre-formatted array, I might create a PHP application to do it, etc. etc.  

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.