0

In mysql table i got entries with those keys should be exclude from the array.

How to echo all array keys without those specifed in mysql table?

<?php
    $a = array("1","2","3","4","5","6","7","8");
?>

In table i have entries with key that should be exlude from array

<?php
    $query=mysql_query("SELECT key FROM table");
    while($get=mysql_fetch_array($query)) {
        $k=$get['key'];
    }
?>

Now i need each $k exclude from $a array and echo all others array keys.

Thank you in advance.

2 Answers 2

2
<?php

    $a = array("1","2","3","4","5","6","7","8");

    $query=mysql_query("SELECT key FROM table");
    while($get=mysql_fetch_array($query)) {
        $k=$get['key'];
        // check $k exists in $a array or not
        if(in_array($k, $a)){
            //get array index here
            $i = array_search($k, $a);
            unset($a[$i]); 
        }
    }
    print_r($a);

?>

It will print array values which are not found in table

Sign up to request clarification or add additional context in comments.

Comments

0

You can use PHP's in_array function to check if current key exists in array.

if( in_array($get['key'], $a) ) {
    continue; // if key exists in $a, skip current iteration
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.