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.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *