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

0

2 Answers 2

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
    )

  )
Sign up to request clarification or add additional context in comments.

4 Comments

i want it in same index.... means my frist array record append into second array record in same index
so is it solve your problem. this is how you want ? if possible can you mark this as answer ?
every thing is good but its not comin in index...
how you want it ? Show a example please
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

1 Comment

I think this is what he wants

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.