0

Help me to reformat my array which is something like this:

Array
(
    [sampleArr] => Array
        (
            [0] => Array
                (
                    [id] => 1
                )

            [1] => Array
                (
                    [id] => 2
                )

        )

)

This is my array need to be reformat like in the above array:

Array
(
    [sampleArr] => Array
        (
            [id] => 1
            [id2] => 2
        )

)
Amboom
  • 156
  • 1
  • 13
  • 6
    Possible duplicate of [How to Flatten a Multidimensional Array?](http://stackoverflow.com/questions/1319903/how-to-flatten-a-multidimensional-array) – splash58 Jul 28 '16 at 08:44
  • 1
    array with same key is not possible. – Niklesh Raut Jul 28 '16 at 08:44
  • 1
    The second array is not valid, you cannot have the same key multiple times. However, `[sampleArr] => Array(0 => 1, 1 => 2)` would work – kero Jul 28 '16 at 08:46
  • sorry i just forgot to notice the same key but i changed it already – Amboom Jul 28 '16 at 08:48

1 Answers1

0

may be you can looping again your array like this.

$data['sampleArr'] = [];
foreach($data['sampleArr'] as $key => $value) {
   $k = !empty($key) ? $key : "";
   $format['sampleArr'][$value['id'].$k] = $value['id'];
}    
cakpep
  • 87
  • 6