Answers for "How to prevent repeating the same option value of a selection in a php loop"

PHP
0

How to prevent repeating the same option value of a selection in a php loop

public function getProductById(Request $request)
    {
        $response = '';
        $product = Product::find($request->productId);
        $groups = Group::all();

        foreach ($groups as $group) {
            if ($group->id != $product->group_id) {
                //exclude this record

                $response .= "<option value='" . $group->id . "'>";
                $response .= $group->group_name;
                $response .= "</option>";
            }
            
        }
    }
Posted by: Guest on May-08-2022

Code answers related to "How to prevent repeating the same option value of a selection in a php loop"

Browse Popular Code Answers by Language