开发者

how do i convert this array?

i have the following array:

["addToCart"]=>
  array(3) {
    [1]=>
    array(5) {
      ["aantal"]=>
      int(1)
      ["film_id"]=>
      string(1) "1"
      ["zaal_id"]=>
      string(1) "1"
      ["dag"]=>
      string(7) "maandag"
      ["seats"]=>
      array(4) {
        [0]开发者_如何学运维=>
        string(2) "67"
        [1]=>
        string(2) "68"
        [2]=>
        string(2) "69"
        [3]=>
        string(2) "70"
      }
    }

You can see that i have an array called "seats" inside the "addToCart" array.There are 4 items in the "seats" array. what i would like to have is 4 separate arrays, they should all have the same content but each of them needs to have 1 value of "seats".


I'm not sure I got exactly what you're looking to do, but this would result in an array of arrays where each has only one seat:

$seatArrays = array();

foreach ($addToCart as $arr)
{
  foreach ($arr["seats"] as $seat)
  {
    $seatArr = $arr;            // Copy the original array
    $seatArr["seats"] = $seat;  // Replace the "seats" subarray with the current seat
    $seatArrays[] = $seatArr;    
  }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜