0

私はこのような配列を持っています

Array
(
    [35635d5ebdd938d6360e65a9e2484073] => Array
        (
            [rowid] => 35635d5ebdd938d6360e65a9e2484073
            [id] => MYU_SC3
            [qty] => 1
            [price] => 4800
            [name] => JAMB UTME Scratch Card
            [service_image] => assets/img/jamb.jpg
            [service_category] => cards
            [subtotal] => 4800
        )

    [d8df18561040f3d9bd9868f5c5aaa7c2] => Array
        (
            [rowid] => d8df18561040f3d9bd9868f5c5aaa7c2
            [id] => MYU_SC1
            [qty] => 1
            [price] => 1600
            [name] => WAEC Scratch Card
            [service_image] => assets/img/waec.jpg
            [service_category] => cards
            [subtotal] => 1600
        )

    [a4a751dd9a69824eb3abb6f49c7a7f61] => Array
        (
            [rowid] => a4a751dd9a69824eb3abb6f49c7a7f61
            [id] => MYU_SC2
            [qty] => 1
            [price] => 1600
            [name] => NECO Scratch Card
            [service_image] => assets/img/neco.jpg
            [service_category] => cards
            [subtotal] => 1600
        )

)

別の配列の要素に一致するサブ配列を取得したい

$card_skus = array("MYU_SC1","MYU_SC2","MYU_SC3");

メイン配列をループしています

foreach ($this->cart->contents() as $key => $item) {
      if(in_array($item['id'], $card_skus))
      {
       //Didn't know what to do at this point
      }
}

どうすればこれを完了できますか、助けてくれてありがとう

4

1 に答える 1

0

@nickb はコメントで既に回答済みだと思いますが、回答を書いている間は表示されませんでした。

これを試して

$subArray = array();
foreach ($this->cart->contents() as $key => $item) {
   if(in_array($item['id'], $card_skus))
   {
      //Didn't know what to do at this point
      $subArray[] = $item;
   }
}

要件に従って、今すぐ $subArray を使用してください

于 2012-07-03T19:10:22.457 に答える