Using php array or using mysql query which one is faster

I don’t honestly know, but I would imagine the array would be faster.
But the problem with the array is: how often with the data set be updated?

When using the database and the same query is being made in a loop, you can make it more efficient by using prepared statements. Prepare the query only once before the loop, then execute within the loop.
Eg:-

$sql = $db->prepare("SELECT * FROM table WHERE id = ?");

foreach($list as $id){
    $sql->execute([$id]);
    // Fetch Etc...
}
1 Like