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.

Recommended Answers

All 3 Replies

No, what is array filter?

Member Avatar for diafol

No, what is array filter?

Did you follow the link ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.