I am trying to compare two different arrays. I am looking for the values that appear in array1 but do not appear in array2. I have been banging my head against the wall about this because it seems so simple but does not work.
I have tried to find the keys of the array and then i was going to search for them
$orgKey;
foreach($org as $k => $v){
$orgKey[$k][] = $v['title'];
}
$newKey;
foreach($new as $k => $v){
$newKey[$k][] = $v['title'];
}
echo "orgkey";
echo print_r($orgKey);
echo "newkey<br/>";
echo print_r($newKey);
$e = array_diff($orgKey,$newKey);
echo print_r($e);
but this gives me an empty array everytime.
I have also tried foreach within foreach and realized i cannot find out how to search through a value that is not there without it duplicating because of the foreach loop itself.
foreach($org as $k => $v){
foreach($new as $a => $b){
$count = count($new);
$i = 0;
if($v['title'] == $b['title']){
//This is where i realize i will find duplicates of values that don't exist
}
}
}
My arrays. $org
[0] => Array
(
[title] => Ahiris Angels
[r_id] => 1276
[t_id] => 1277
[name] =>
[column1] =>
[column2] =>
)
[1] => Array
(
[title] => Alistars Stars
[r_id] => 1276
[t_id] => 1278
[name] =>
[column1] =>
[column2] =>
)
[2] => Array
(
[title] => Ammumu
[r_id] => 1276
[t_id] => 1279
[name] =>
[column1] =>
[column2] =>
)
The $new array can be any values but keeps the structure of the $org array.
My Goal is to have an array like this $org
[0] => Array
(
[title] => Ahiris Angels
[r_id] => 1276
[t_id] => 1277
[name] =>
[column1] =>
[column2] =>
)
[1] => Array
(
[title] => Alistars Stars
[r_id] => 1276
[t_id] => 1278
[name] =>
[column1] =>
[column2] =>
)
Compare it to $new
[0] => Array
(
[title] => Ahiris Angels
[r_id] => 1276
[t_id] => 1277
[name] =>
[column1] =>
[column2] =>
)
And my Result will be
[1] => Array
(
[title] => Alistars Stars
[r_id] => 1276
[t_id] => 1278
[name] =>
[column1] =>
[column2] =>
)