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);
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3ec78-2c434.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3ec78-2c434.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?