samedi 20 mars 2021

Loop Foreach PHP With Specific Separator From Checkbox

can you help me

I have output like this

enter image description here

I want the output like this

enter image description here

This my script

$p_modules = $_POST['modules'];
$total_modules = count($p_modules);

$i = 0;
$module_name = "";

foreach($p_modules as $modules) {
    $i++;

    $exp_module = explode("-", $modules);

    if(count($exp_module) == 1) {
        $module_name .= ($total_modules != $i) ? $modules.", " : $modules."";
    }
    else {
        list($main_module, $sub_module) = $exp_module;

        if($total_modules != $i) {
            $module_name .= $modules.";";
        }
        else {
            $module_name .= $modules."";
        }
    }
}

echo json_encode(array("success"=>true, "desc"=>$module_name));

My output :
meals-transaction;meals-order;meals-manage_orders;meals-report;meals_order, employees, modules, user-profile;user-change_password;user-logout;tes

I want :
meals-transaction;meals-order;meals-manage_orders;meals-report, meals_order, employees, modules, user-profile;user-change_password;user-logout, tes

Any tricks to make it?

Many Thanks!




Aucun commentaire:

Enregistrer un commentaire