How can PHP arrays be effectively utilized to store and manipulate server data for optimal cost calculations in a dynamic environment?
To store and manipulate server data for optimal cost calculations in a dynamic environment using PHP arrays, you can create an associative array where the keys represent the server names and the values represent the cost associated with each server. You can then use array functions like array_sum() to calculate the total cost or array_filter() to filter out specific servers based on criteria.
// Create an associative array to store server data
$servers = [
'server1' => 100,
'server2' => 150,
'server3' => 200
];
// Calculate the total cost of all servers
$totalCost = array_sum($servers);
// Filter out servers with a cost greater than 150
$expensiveServers = array_filter($servers, function($cost) {
return $cost > 150;
});