Assume that I have an array like this:
Array
(
[0] => Array
(
[0] => John
[1] => accountant
[2] => senior
[3] => joined on 2018-03-12
[4] => http://personalblog[dot]com/abc
[5] => Germany
)
[1] => Array
(
[0] => Marry
[1] => journalist
[2] => junior
[3] => 2019-04-13
[4] => http://personalblog[dot]com/efd
[5] => Canada
)
[2] => Array
(
[0] => Jim
[1] => salesman
[2] => junior
[3] => 2017-01-18
[4] => http://personalblog[dot]com/ehs
[5] => US
)
[3] => Array
(
[0] => Clair
[1] => director assistant
[2] => senior
[3] => 2019-08-22
[4] => http://personalblog[dot]com/khh
[5] => Singapore
)
)
And I have a table like this:
id name ... Date_joined
---------------------------------
1 Jack ... 2019-07-25
2 Clair ... 2019-08-22
3 Jim ... 2017-01-18
I do a foreach loop
to get the values
of the array above like this:
foreach ($arr as $key => $value){
echo $value.'<br />';
}
Then I retrieve the table's name column
by using the SELECT
query like this:
$query = "SELECT name FROM tabeName";
$r = mysqli_query($dbc, $query);
while($row = mysqli_fetch_array($r, MYSQLI_ASSOC)){
echo $row['name'].'<br />';
}
What I would like to get is to compare the one of the array values, * with the names from the table so that I can print
ONLY the array values which have not been in the table so far, which are Marry, and John.
I got stuck at this step, because I have tried the if
conditional inside the while loop
like this:
if($row['name']!= $value[0]){
echo $value[0].'<br />';
}else{
echo 'No new value found';
}
but I just got all the names from the table for 3 times instead of the ONLY new array values from the array which have the new names of Marry, and John, as desired.