How can references be effectively used in PHP arrays when working with bindParam in PDO prepared statements?

When using bindParam in PDO prepared statements in PHP, references can be effectively used by passing the variable by reference in the array. This allows for the variable to be bound to the prepared statement and any changes to the variable will be reflected in the bound parameter.

// Example of using references in PHP arrays with bindParam in PDO prepared statements
$pdo = new PDO("mysql:host=localhost;dbname=mydatabase", "username", "password");

// Prepare a SQL statement with a placeholder for a parameter
$stmt = $pdo->prepare("SELECT * FROM users WHERE id = :id");

// Define the variable to be bound to the parameter
$id = 1;

// Bind the variable by reference in the array
$stmt->bindParam(':id', $id, PDO::PARAM_INT);

// Execute the statement
$stmt->execute();

// Fetch the results
$results = $stmt->fetchAll();

// Output the results
print_r($results);