troubleshooting Question

Saving 2 arrays into one combined json value for DB column

Avatar of tjyoung
tjyoung asked on
PHPJSON
12 Comments2 Solutions122 ViewsLast Modified:
Hi,
I have a form that submits a series of checkboxes in an array and corresponding values in another array.

$_POST['specs']['checks'];
$_POST['specs']['values'];

I var_dumped to give you an idea.

Array ( [horsepower] => 1 [horsepower_rpm] => 1 [torque] => 1 [torque_rpm] => 1 [fuel_capacity] => 1 [vehicle_length] => 1 [vehicle_width] => 1 [vehicle_height] => 1 [curb_weight] => 1 )

Array ( [horsepower] => 170.0 [horsepower_rpm] => 5800 [torque] => 174.0 [torque_rpm] => 4100 [fuel_capacity] => 64.0L [vehicle_length] => 179.5 in [vehicle_width] => 70.1 in [vehicle_height] => 66.9 in [curb_weight] => 3307.0 lbs ) 
I need to combine these 2 as json and insert into a DB column so it ends up looking like this:
{"checks":["horsepower","horsepower_rpm","torque","torque_rpm","fuel_capacity","vehicle_length","vehicle_width","vehicle_height","curb_weight"],"values":{"horsepower":"170.0","horsepower_rpm":"5800","torque":"174.0","torque_rpm":"4100","fuel_capacity":"64.0L","vehicle_length":"179.5 in","vehicle_width":"70.1 in","vehicle_height":"66.9 in","curb_weight":"3307.0 lbs"}}
any idea how I can get there? I've tried a few dozen different combinations but not working out at all.
Thanks as always.
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 2 Answers and 12 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 12 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros