I am trying to compare a JSON return with set ARRAY.
The JSON is showing OK, this is set as $a. The ARRAY is coded and is showing OK, this is set as $b.
I'd like the output to be a percentage, not including duplicates.
THIS IS NOW EDITED.
<?php
$loggedUser = auth()->user()->id ; // returns authenticated user id.
$pdo = new PDO('mysql:host=****;dbname=****', '****', '****');
$stmt = $pdo->prepare('SELECT movie_id FROM user_watch_lists WHERE user_id = :user');
$stmt->execute(array('user' => $loggedUser));
$result_array = $stmt->fetchAll(PDO::FETCH_ASSOC);
$a = $result_array;
$b = array(297761);
print_r($a);
print_r($b);
$c = 0;
foreach ($a as $k=>$v) {
if ($v == $b[$k]) $c++;
}
echo ($c/count($a))*100;
?>
Contents of the return above (echo $a; and $echo b; and echo ($c/count($a))*100;):
Array ( [0] => Array ( [movie_id] => 297761 ) )
Array ( [0] => 297761 )
0
This should return 100%. I can see why, but unsure how to fix. I've tried to change the loop to go in to the array but get ERROR.
foreach ($a as $r=>$k=>$v) {
if ($v == $b[$k]) $c++;
}
echo ($c/count($a))*100;