I have fetched the value from database using query and trace the variable using foreach. I want to get the mail id append with the variable $cc_test
.
Initially the variable is empty. for first iteration test@sample.com
2nd iteration test1@sample.com
and for 3rd test2@sample.com
.
Finally I want to get test@sample.com,test1@sample.com,test2@sample.com
, but now I get 'test2@sample.com,test2@sample.com
'.
$cc_check
is an indexed array print_r($cc_test)
in for loop prints test@sample.com
for 1st and test1@sample.com
for 2nd and so on.
$cc_check=asset_status_tracker::where('request_id','=',$data['id'])->where('status_before','!=',null)->get();
$cc_test=''; //dump requestor mail id
foreach($cc_check as $cc_inner){
$cc_mail=$cc_inner->changed_by;
print_r($cc_mail);
$cc_test=users::where('id','=',$cc_mail)->first()->mail;
$cc_test=$cc_test.','.$cc_test;
//print_r($cc_test);
}
print_r($cc_test); //test@sample.com,test1@sample.com,test2@sample.com