小编Raz*_*mun的帖子

如何访问array_walk中的其他变量?

我有一个变量$id = 10,需要在里面使用array_walk().如下:

$id = 10;
array_walk($profile_items, function(&$a) {
    $count = $this->db->where('profile_item_id', $a['id'])->where('cover_type_id', $id)->count_all_results('cover_type_profile_items_link');
    $a['selected'] = $id;
});
echo "<pre>";
print_r($profile_items).exit;
Run Code Online (Sandbox Code Playgroud)

当我在其中使用$id变量时array_walk()显示错误.

消息:未定义的变量:id

有解决方案吗

谢谢你的建议

php parameters codeigniter array-walk

2
推荐指数
1
解决办法
1120
查看次数

标签 统计

array-walk ×1

codeigniter ×1

parameters ×1

php ×1