What are the potential pitfalls of using complex array structures in SQL queries in PHP?

Using complex array structures in SQL queries in PHP can lead to SQL injection vulnerabilities if the array data is not properly sanitized or escaped. To avoid this issue, it's recommended to use prepared statements with placeholders for dynamic values in the query.

// Example of using prepared statements to avoid SQL injection with complex array structures

// Assuming $conn is a valid database connection object

// Sample complex array structure
$data = [
    'name' => 'John Doe',
    'age' => 30,
    'email' => 'johndoe@example.com'
];

// Prepare the SQL statement with placeholders
$stmt = $conn->prepare("INSERT INTO users (name, age, email) VALUES (?, ?, ?)");

// Bind the parameters to the placeholders
$stmt->bind_param("sis", $data['name'], $data['age'], $data['email']);

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

// Close the statement and connection
$stmt->close();
$conn->close();