If you want to create an associative array in php5, which is the correct manner?
-
$var = new asoc_array("key"->"value","key2"->"value2");
-
$var = array("key"=>"value","key2"=>"value2");
-
$var = new ArrayList("key,value","key1,value1");
-
$var = new List(Of Associative)["key"=>"value","key1","value1"];
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.