I pull live data and plug it in to one array. The code below pulls from a local database which is then used to check against the live array data. If there is a match, number is not listed. The code below works but is there a more efficient way to do this?    $results = array();$result = mysqli_query($conn, $sqlquery);                if(mysqli_num_rows($result)>0){                    while ($row = mysqli_fetch_assoc($result)) {                        $results[] = $row;                    }                }            $mainarray = array();            foreach($results as $key => $value){                $mainarray[] = $value['NUMBER'];            }            $str = implode (, , $mainarray);            $myArray = explode(',', $str);
Is there a cleaner way to write all these foreach and arrays together?
performance;php
Although it's hard to tell what this code is intended to do, but at least two suggestions could be made:First, there is no point in looping twice. Why don't you collect the data in the $mainarray already? Something like this:$mainarray = array();$result = mysqli_query($conn, $sqlquery);while ($row = mysqli_fetch_assoc($result)) {    $mainarray[] = $row['NUMBER'];}Second, an obligatory suggestion to use PDO instead of mysqli could be made. In this case, the whole stuff could be written in a single line$mainarray = $stmt->fetchAll(PDO::FETCH_COLUMN);given $stmt contains a PDO query result and NUMBER field has been listed alone in the filed list in SQL