-1

I have 3 array below from html textbox txt_job_exp_start[], txt_job_exp_end[] ,txt_job_exp_desc[] and i want to join them together using laravel 7 or any method.

array:3 [▼
  "txt_job_exp_start" => array:3 [▼
    0 => "2019-03"
    1 => "2018-12"
    2 => "2017-12"
  ]
  "txt_job_exp_end" => array:3 [▼
    0 => "2020-02"
    1 => "2019-11"
    2 => "2018-08"
  ]
  "txt_job_exp_desc" => array:3 [▼
    0 => "Description 1"
    1 => "Description 2"
    2 => "Description 3"
  ]
]

This is the result i want. please kindly help me.

array:3 [▼
  0 => array:3 [▼
    "start" => "2019-03"
    "end"  => "2020-02"
    "description"  => "Description 1"
  ]
  1 => array:3 [▼
    "start"  => "2018-12"
    "end"  => "2019-11"
    "description"  => "Description 2"
  ]
  2 => array:3 [▼
    "start"  => "2017-12"
    "end"  => "2018-08"
    "description"  => "Description 3"
  ]
]
Smith Foto
  • 159
  • 12

2 Answers2

2

You can use array_map with first value of null to zip as many arrays as you want as stated in php.net.

Below code may help you.

$txt_job_exp_start = [];
$txt_job_exp_end = [];
$txt_job_exp_desc = [];

$result = array_map(null, $txt_job_exp_start, $txt_job_exp_end, $txt_job_exp_desc)
SEYED BABAK ASHRAFI
  • 4,093
  • 4
  • 22
  • 32
0

you have that array just run a loop through it and store the values in an empty array.

foreach($arr as $key => $val){
    $arr2[] = $val;
}
var_dump($arr2);

demo here

bhucho
  • 3,903
  • 3
  • 16
  • 34