troubleshooting Question

PHP array keys

Avatar of ScotTFO
ScotTFOFlag for United States of America asked on
PHP
10 Comments1 Solution123 ViewsLast Modified:
I am querying an API and it sends a JSON response which I am then decoding into an array.  This part works fine, but the API sends the information in a rather unfriendly format.

I will paste the part I am having issues with.  Essentially I am trying to change each like keys into their own array.
Array
(
    [name] => Name
    [address] => 123 Street Rd
    [products[0][product_id]] => 1
    [products[0][price]] => 12.00
    [products[0][name]] => Product Name
    [products[0][product_qty]] => 1
    [products[1][product_id]] => 2
    [products[1][price]] => 3.00
    [products[1][name]] => Product Name
    [products[1][product_qty]] => 1
    [systemNotes[0]] => Note 1
    [systemNotes[1]] => Note 2
)
[
Now what I would like to do is to make
it like this:

Array
(
    [name] => Name
    [address] => 123 Street Rd
	[product] => Array
	(
		[0] => Array
		(
			[product_id] => 1
			[price] => 12.00
			[name] => Product Name
			[product_qty] => 1
		)
		[1] => Array
		(
			[product_id] => 2
			[price] => 3.00
			[name] => Product Name
			[product_qty] => 1
		)
    [systemNotes] => Array
	(
		[0] => Note 1
		[1] => Note 2
	)
)
[
Is there any practical way of doing this?

Thanks!
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 10 Comments.
Join the Community
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 1 Answer and 10 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