复杂的每个检索数组值



我目前正在研究一个项目,该项目创建了一个多维数组。print_r()的结果如下:

Array ( 
[campaigns] => Array ( 
    [0] => Array ( 
        [CampaignId] => 1 
        [DID] => 2394434444 
        [FWDDID] => 3214822821 
        [ProductId] => 1 
        [CampaignName] => Fort Myers Bus #1 
        [ProductName] => CallTrack - Sharktek 
        [Active] => 1 [CompanyId] => 1 ) 
    [1] => Array ( 
        [CampaignId] => 4 
        [DID] => 2394434445 
        [FWDDID] => 3214822821 
        [ProductId] => 1 
        [CampaignName] => Cape Coral Billboard #2 
        [ProductName] => CallTrack - Sharktek 
        [Active] => 1 [CompanyId] => 1 ) 
    [2] => Array ( 
        [CampaignId] => 5 
        [DID] => 2392146000 
        [FWDDID] => 3214822821 
        [ProductId] => 1 
        [CampaignName] => Test Campaign 
        [ProductName] => CallTrack - Sharktek 
        [Active] => 1 
        [CompanyId] => 1 )
    ) 
)

我正试图创建一个foreach循环,选择所有的campaign id,并在另一个循环中使用它们,不幸的是,我没能这样做。

因为我使用的是CodeIgniter,所以我无法在控制器中简单地回显结果,而是必须将我想要的值传递给另一个数组以发送给视图

感谢您的时间和努力,任何帮助将不胜感激!

如果你只是想让所有的活动id到foreach之后,你有PHP>= 5.5.0,然后使用array_column:

$ids = array_column($array, 'CampaignId');

If PHP <5.5.0 then foreach over $array['campaigns'] .

foreach($array['campaigns'] as $campaign) {
    $ids[] = $campaign['CampaignId'];
}

相关内容

  • 没有找到相关文章

最新更新