ExamVeda
Login
Home
This question belongs to PHP Arrays
Arrays
?

Which of the following are correct ways of creating an array?
1. state[0] = “karnataka”;
2. $state[] = array(“karnataka”);
3. $state[0] = “karnataka”;
4. $state = array(“karnataka”);

Answer & Solution
Correct Answer: Option A
A variable name should start with $ symbol which is not present in i) and you need not put the square brackets when you use the array() constructor.
Examveda
Question posted by Examveda
Community

Join the Discussion

1 Comment
John Williams
John Williams 8 years ago
Answer 2 is legit also. You would be creating an array with single string value 'karnataka' as a value inside the array $state