Php two-dimensional array deletes elements according to id!


the iduser in the array is the iduser, saved by the current login account, and then delete the entire element according to the iduser of the current login account. For example, if the login iduser is 636, delete the element of subscript 1. If it is 686, delete the element of subscript 0.

Aug.05,2021

take a look at the PHP function, I hope it can help you! clipboard.png


just use the loop to determine whether iduser is equal or not.

function repeat(array $input, string $key, int $user_id): array
    {
        
        
        foreach ($input as $k => $v) {
            if ($input[$v[$key]] == $user_id) {
                unset($input[$k]);
                break;
            }
            
            continue;
        }
        
        
        return $input;
    }
    
    
    var_dump (repeat ($data, 'iduser', 686));

        $login_id = 686;
        foreach ($data as $key => $value) {
            if($value['iduser'] == $login_id){
                unset($data[$key]);
            }
        }
        
        print_r($data);
Menu