Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

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>";
            }
            
        }
    }
 
PREVIOUS NEXT
Tagged: #How #prevent #repeating #option #selection #php #loop
ADD COMMENT
Topic
Name
1+2 =