What are some best practices for streamlining and optimizing array manipulation in PHP when dealing with database query results?

When dealing with database query results in PHP, it is important to streamline and optimize array manipulation to improve performance. One way to achieve this is by using functions like array_map, array_filter, and array_column to manipulate arrays efficiently.

// Example code snippet for optimizing array manipulation with database query results
$query = "SELECT * FROM table_name";
$result = mysqli_query($connection, $query);

// Fetch query results into an associative array
$data = [];
while ($row = mysqli_fetch_assoc($result)) {
    $data[] = $row;
}

// Extract specific column values into a new array using array_column
$columnValues = array_column($data, 'column_name');

// Filter array based on a condition using array_filter
$filteredData = array_filter($data, function($row) {
    return $row['column_name'] > 10;
});

// Perform a custom operation on each element using array_map
$modifiedData = array_map(function($row) {
    $row['new_column'] = $row['column_name'] * 2;
    return $row;
}, $data);