Which of the following is the correct way to define an associative array in PHP?
- $colors = ['red' => '#FF0000', 'green' => '#00FF00', 'blue' => '#0000FF']
- $colors = ['red', 'green', 'blue']
- $colors = ('red' => '#FF0000', 'green' => '#00FF00', 'blue' => '#0000FF')
- $colors = {'red' => '#FF0000', 'green' => '#00FF00', 'blue' => '#0000FF'}
The correct way to define an associative array in PHP is by using the format shown in Option 1, where keys are associated with values using the => symbol.
Loading...
Related Quiz
- What keyword is used in PHP to access a global variable inside a function?
- You are writing a PHP script and you want to execute a block of code a fixed number of times. How would you do this using a for loop?
- How can you implement secure password hashing in PHP? Discuss the password_hash() and password_verify() functions.
- What are some common uses of the $_SESSION superglobal array in PHP?
- How can you decode a JSON object into a PHP array?