如果我改变$resultado_frontend使用array_filter它只在函数内部改变它,如果在它是一个空数组$resultado_frontend之后尝试访问。array_filter
$resultado_frontend = [];
$contas_b2w = array_filter($contas->toArray(), function($conta) use($id_admin, $resultado_frontend, $json_tiao) {
if($conta['id_mkt'] == 3){
$sku_existe = Anuncio::where([['id_admin', $id_admin], ['conta_id', $conta['id']]])->where('json_jcontrole->sku', $json_tiao['sku'])->first();
if($sku_existe){
$resultado_frontend[] = ["essa conta já possui o sku cadastrado para este marketplace"];
dd($resultado_frontend); // here the string is inserted into the array
}else{
return $conta;
}
}
});
dd($resultado_frontend); //If a remove the "dd" inside the closure and let code reach this "dd", the array will be empty. How can I get around this?