How can you add a new key to an array in PHP?
To add a new key to an array in PHP, you can simply assign a value to a new key in the array using the square bracket notation. This will automatically create the new key if it doesn't already exist.
// Create an array
$array = array("key1" => "value1", "key2" => "value2");
// Add a new key to the array
$array["key3"] = "value3";
// Print the updated array
print_r($array);
Related Questions
- What best practices should be followed when handling session management and user authentication in PHP to prevent system vulnerabilities?
- What is the recommended method to check if a user is online in PHP?
- What potential issues could arise when using the INSERT INTO command in PHP to insert data into a MySQL database?