How can one access and store specific values from an array obtained from a SQL query in PHP using PDO?

To access and store specific values from an array obtained from a SQL query in PHP using PDO, you can fetch the results as an associative array and then access the specific values by their keys. You can store these values in variables for further use in your code.

// Assuming $pdo is your PDO connection and $query is your SQL query

$stmt = $pdo->query($query);
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);

foreach ($results as $result) {
    $specificValue1 = $result['column_name1'];
    $specificValue2 = $result['column_name2'];
    
    // Use the specific values as needed
}