-1

I have a php array that outputs a json like this:

"extraDetails":[
{
"basic":{
"0":{
"id":"101"
},
"1":{
"details":"176381954"
},
"16":{
"birth_date":"1\/15\/1973"
}
]

There are multiple headings like extraDetails. the problem is, I want everything to move one up that has a number. Like so: Basically I want to remove the 0, 1, and 16 and whatever arbitrary number comes from the json.

"extraDetails":[
{
"basic":{
"id":"101"
"idTest":"101"
"idTest2":"101"
},
"details":"176381954"
"MoreDetails":"176381954"
},
"birth_date":"1\/15\/1973"
}
]

UPDATE: This is the array:

array(1) {
basic info=>
array(16) {
  [0]=>
  array(1) {
    ["id"]=> string(7) "1798919"
  }
  [1]=>
  array(1) { ["Somevalue"]=>
    string(9) "164315268"
  }
  [16]=>
  array(1) {
    ["Somevalue"]=>
    string(9) "2/15/1977"
  }
  [18]=>
  array(1) {
    ["Somevalue"]=>
    string(5) "White"
  }
  [20]=>
  array(1) {
    ["Somevalue"]=> string(2) "40"
  }

UPDATE: This is what I want it to ideally look like:

array(1) {
basic info=>
array(16) {
 array(1) {
    ["id"]=> string(7) "1798919"
  }
    array(1) { ["Somevalue"]=>
    string(9) "164315268"
  }
  array(1) {
    ["Somevalue"]=>
    string(9) "2/15/1977"
  }
  array(1) {
    ["Somevalue"]=>
    string(5) "White"
  }
  array(1) {
    ["Somevalue"]=> string(2) "40"
  }
9
  • Can you show the code which generates the array? Commented Jun 20, 2019 at 19:23
  • Hi. I don't have it, I only get a json feed. From that I reconvert it to an array Commented Jun 20, 2019 at 19:25
  • So show the PHP array and how you want it to look, that's easier than changing the JSON. Commented Jun 20, 2019 at 19:26
  • @AbraCadaver Updated Commented Jun 20, 2019 at 19:33
  • 1
    Not sure if it's a duplicate of stackoverflow.com/questions/11195692/…, have a read and see what you think. Commented Jun 20, 2019 at 19:43

1 Answer 1

0

The keys are unique in the JSON but not in the PHP array so I'll assume that is copy paste issue or something. If the indexes are unique then just merge them (PHP >= 5.6.0):

$array['basic info'] = array_merge(...$array['basic info']);

For older versions:

$array['basic info'] = call_user_func_array('array_merge', $array['basic info']);
Sign up to request clarification or add additional context in comments.

2 Comments

Its a copy paste issue. the indexes are also not unique. This json has over 200 headers and 6000 possible fields, no way to write it out. Has to be a variable with a foreach loop to just remove the index-counter (I assume) in the front.
Did this work? You have to adjust based on whether it's really basic or basic info or whatever. Lot's of discrepancies.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.