Split your carry using if statement
$alerts =
[[
'user_id' => $i,
'reference' => $faker->sentence($nbWords = 1),
'type' => rand(1,2),
'category' => rand(1,4),
'headline' => $faker->sentence($nbWords = 2),
'description' => $faker->realText(150)
]];
foreach($alerts as $key=>$alert){
if( $alert['type'] != 1 ){
$alerts[$key]['category'] = $alerts[$key]['headline'] = $alerts[$key]['description'] = NULL ;
}
}
So you set your alerts as you want, then you loop on them and apply the condition you want if it exist then you edit the array.
in above example it will loop $alerts
and for each array if ['type'] not equal 1 it will set category,headline and description of that array to NULL..