What are some common pitfalls to avoid when working with arrays and SQL queries in PHP?

One common pitfall when working with arrays and SQL queries in PHP is not properly sanitizing user input, which can lead to SQL injection attacks. To avoid this, always use prepared statements with parameterized queries to prevent malicious input from affecting your database.

// Example of using prepared statements to prevent SQL injection
$stmt = $pdo->prepare('SELECT * FROM users WHERE username = :username');
$stmt->execute(['username' => $username]);
$user = $stmt->fetch();