-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"
  }

1 Answers1

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']);
AbraCadaver
  • 78,200
  • 7
  • 66
  • 87
  • 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. – Alex Yeskov Jun 20 '19 at 19:42
  • Did this work? You have to adjust based on whether it's really `basic` or `basic info` or whatever. Lot's of discrepancies. – AbraCadaver Jun 20 '19 at 20:14