我有以下数据结构:$campaigns =Array([0] => Array ( [subject] => cca-cpg )[1] => Array ( [subject] => cleanup-cpg )[2] => Array ( [subject] => gas-cpg )[3] => Array ( [subject] => pollinators-cpg ))我想结束的是:$campaigns = ['cca-cpg','clean_up-cpg','gas-cpg','pollinators-cpg'];this will work:$newCampaigns=[];for($i=0;$i<count($campaigns);$i++){ array_push($newCampaigns,$campaigns[$i]['subject'];}但我想知道是否有更好的方法来做到这一点。数据直接来自mysql数据库
1 回答
慕娘9325324
TA贡献1783条经验 获得超4个赞
有适合array_column()
你的功能:
$newCampaigns = array_column($campaigns, 'subject');
- 1 回答
- 0 关注
- 90 浏览
添加回答
举报
0/150
提交
取消