Multiple choice technology web technology

If you want to create an associative array in php5, which is the correct manner?

  1. $var = new asoc_array("key"->"value","key2"->"value2");
  2. $var = array("key"=>"value","key2"=>"value2");
  3. $var = new ArrayList("key,value","key1,value1");
  4. $var = new List(Of Associative)["key"=>"value","key1","value1"];
Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

PHP associative arrays are created using the array() function with the => operator to associate keys with values. Option B shows the correct syntax: $var = array("key"=>"value", "key2"=>"value2"). Option A uses incorrect -> syntax and non-existent constructor. Option C is Java-style syntax. Option D is C# style syntax.