-3

I want to use foreach in an array and this foreach uses an array. The code is here:

$records["data"][] = array(
  $id,
$value['name'],
foreach($kichen_organ as $x => $x_value){  if($value['organ']==$x) '<span class="badge badge-success">'echo $x_value;'</span>' },
$value['type'] ,
$value['name_responsible'] ,
$value['family_responsible'] ,
$value['office'],
$value['fax'],
$value['mobile']);

$kichen_organ is another array that I parse it's key and value by renaming $x and $s_value but I received this error:

syntax error, unexpected 'foreach' (T_FOREACH), expecting ')' in /var/www/html/...

What's the solution for using the loop in array?

1 Answers1

0
$temp = [];

foreach($kichen_organ as $x => $x_value) {
    if ($value['organ'] == $x) {
        $temp[] = '<span class="badge badge-success">'.$x_value.'</span>';
    };
}

$records["data"][] = array_merge($temp,
    [
        $id,
        $value['name'],
        $value['type'] ,
        $value['name_responsible'] ,
        $value['family_responsible'] ,
        $value['office'],
        $value['fax'],
        $value['mobile']
    ]);
rokas
  • 1,521
  • 9
  • 16