Home > Net >  I need to remove a single array within a 2d array and form associative array
I need to remove a single array within a 2d array and form associative array

Time:12-17

I'm getting this in my post,

[{"master":"80216","assign":["80491","80514","80575"]}]

Required Output

[{"master":"80216","assign":"80491"}]
[{"master":"80216","assign":"80514"}]
[{"master":"80216","assign":"80575"}]

CodePudding user response:

This will do the trick. No explanation is needed. You can get it by going through the code.

$input  = []; # your data array

foreach ($input as $item) {
    $master = $item["master"];
    foreach ($item["assign"] as $assign) {
        $output[] = [
            "master" => $master,
            "assign" => $assign
        ];
    }
}
  • Related