Search
 
SCRIPT & CODE EXAMPLE
 

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>";
            }
            
        }
    }
Comment

PREVIOUS NEXT
Code Example
Php :: woocommerce subscriptions custom user rolde 
Php :: Loading an image using a PHP script 
Php :: trait class has consttoctor 
Php :: ubuntu add phpstorm to launcher 
Php :: hi we add file in orders the other hide and order show in laravel view 
Php :: php Change the WooCommerce loop product link based on a custom field 
Php :: sync fetch eloquent laravel 
Php :: laravel factory counter 
Php :: test lockForUpdate laravel 
Php :: php check if variable is true or false 
Php :: php linkify text 
Php :: php doctrine findby greater than 
Php :: Display out of stock products last (even after sort) - Woocommerce 
Php :: nl2br is not working for database in php 
Php :: generate hash password in laravel online 
Php :: laravel schedule run 
Php :: modal align center yii2 
Php :: php magic __dir__ since ? 
Php :: Available excel column formatting 
Php :: add backslash to path wordpress 
Php :: php edit user profile 
Php :: function to fetch user details 
Php :: laravel view 
Php :: SELECT * FROM `phptrip` WHERE `dest`=`BIHAR` LIMIT 0, 25 
Php :: newrelic notice err with custom attributes 
Php :: Donut chart in PHP 
Php :: how to get file name in upload images in php 
Php :: deleted_at 
Php :: php get long word in array 
Php :: Add ACF to single.php 
ADD CONTENT
Topic
Content
Source link
Name
1+2 =