0

I have a query that selects data and places it into an array. This array can contain 'null' as a results. I want to remove all the varaibles that say 'null'. I have a code that is suppse to remove all the null variables but instead it replaces them with numbers?

Here is my Code

 $query = "SELECT * FROM test WHERE $info = '$search1' ORDER BY id DESC";
            $results = mysql_query($query);

            while($row = mysql_fetch_array($results)){

                $Array[] = $row['first_names'];
                $Array[] = $row['last_names'];

            }//end while mysql_fetch_array

           foreach (array_keys($Array, 'null') as $key) {
                 unset($Array[$key]);
            }

The results I get look like this

[ 1:"Bob", 3:"Smith"]

if I remove the foreach function the results look like this,

["null","Bob","null","Smith"]

I don't know where the numbers are coming from, but don't be confused about me setting the Array[] to different values. I want the first name and last name in serperate quotations. Some people dont have last names so the space is filled with a 'null' and I am trying to remove all the nulls.

Edited by pritaeas: Moved to PHP.

3
Contributors
3
Replies
25
Views
3 Years
Discussion Span
Last Post by diafol
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.