What are some potential pitfalls to be aware of when using arrays in PHP to manipulate data from a database table?

One potential pitfall when using arrays in PHP to manipulate data from a database table is the risk of SQL injection attacks if user input is not properly sanitized. To prevent this, always use prepared statements with parameterized queries to securely interact with the database.

// Example of using prepared statements to safely query a database table
$pdo = new PDO("mysql:host=localhost;dbname=mydatabase", "username", "password");

$stmt = $pdo->prepare("SELECT * FROM users WHERE username = :username");
$stmt->bindParam(':username', $username);
$stmt->execute();

$result = $stmt->fetchAll(PDO::FETCH_ASSOC);

foreach ($result as $row) {
    // Manipulate data from the database table
}