Explain Creating and Naming an Array?



Explain Creating and Naming an Array?..

Answer / Sourabh Gupta

In PHP, you can create an array using several methods.
1. Using array() - Creates an associative or indexed array.n Example: `$colors = array("red", "blue", "green"); $myArray = array("name" => "John", "age" => 30);`
2. Using square brackets [] - Creates an indexed array.n Example: `$colors = ["", "blue", "green"];`nFor naming an array, follow the same rules as for naming variables:
1. Only letters (A-Z, a-z), numbers (0-9), underscores (_), and dollars ($) are allowed.
2. The first character cannot be a number or underscore.
3. Names must NOT contain spaces.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More PHP Interview Questions

how many error types in php? name there?

5 Answers  


What is the difference between echo, print and printf()?

1 Answers  


Tell me how the result set of mysql be handled in php?

1 Answers  


What is difference between single quotes and double quotes in php?

1 Answers  


How are sessions maintained?

1 Answers  


what is constructor

1 Answers  


Why delimiter is used in mysql?

1 Answers  


What is an example of a variable?

1 Answers  


Write a hello world program using variable?

1 Answers  


What is the use of magic function in php?

1 Answers  


What is php? Why it is used?

1 Answers  


Tell me how to find the length of a string?

1 Answers  


Categories