0

I have two array, i want to convert it with one array with whole data. My array format is here

$fromData=array('id' => '004','shapeid' => 'circle','x' =>'360','y' => '560', 'tooltext' => 'vivek','labelpos' => 'bottom'); 

$ToData=array('id' => '005','shapeid' => 'triangle','x' =>'480','y' => '980', 'tooltext' => 'kimi','labelpos' => 'top'); 

I wanna got whole data in one array.

Thanks

Lets-c-codeigniter
  • 682
  • 2
  • 5
  • 18
Vivek Mishra
  • 37
  • 1
  • 7

2 Answers2

1

you can use array_merge_recursive

$fromData=array('id' => '004','shapeid' => 'circle','x' =>'360','y' => '560', 'tooltext' => 'vivek','labelpos' => 'bottom'); 

$ToData=array('id' => '005','shapeid' => 'triangle','x' =>'480','y' => '980', 'tooltext' => 'kimi','labelpos' => 'top'); 


$newdata=  array_merge_recursive($fromData,$ToData);

output will be

Array
(
[id] => Array
    (
        [0] => 004
        [1] => 005
    )

[shapeid] => Array
    (
        [0] => circle
        [1] => triangle
    )

[x] => Array
    (
        [0] => 360
        [1] => 480
    )

[y] => Array
    (
        [0] => 560
        [1] => 980
    )

[tooltext] => Array
    (
        [0] => vivek
        [1] => kimi
    )

[labelpos] => Array
    (
        [0] => bottom
        [1] => top
    )

  )
Amit Sharma
  • 1,775
  • 3
  • 11
  • 20
0

This can be done based on what @Ajith is suggesting in above comment

$result[] = $fromData;
$result[] = $ToData;

You can check this implementation here, https://3v4l.org/0QR56

rathodbhavikk
  • 416
  • 7
  • 20