Change language

Difference between array () and [] in PHP

Syntax:
array (key = > value, key2 = > value2, key3 = > value3, ...) 
The comma after the last element of the array is not required, but it can help other developers understand if the array is being updated or not. This is usually done for single-line arrays, i.e. array (1, 2) is preferred over array (1, 2,). On the other hand, a trailing comma is usually used for multi-line arrays because it makes it easier to add new elements to the end of an existing array.Note.The only difference is using [] or array() depends on the PHP version you are using. In PHP 5.4, you can also use the short array syntax, which replaces array() with [].Example : $array = array ( "geek" = > "tech" , "tech " = > " geek " , ); var_dump ( $array );  
// Since PHP 5.4 $array = [ "geek" = > "tech" , "tech" = > "geek" , ]; var_dump ( $array ); ?>
Output:
array (2) {["geek"] = > string (4) "tech" ["tech"] = > string (4) "geek"} array (2) {["geek"] = > string (4) "tech" ["tech"] = > string (4) "geek"} 

Shop

Best laptop for Sims 4

$

Best laptop for Zoom

$499

Best laptop for Minecraft

$590

Best laptop for engineering student

$

Best laptop for development

$

Best laptop for Cricut Maker

$

Best laptop for hacking

$890

Best laptop for Machine Learning

$950

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers

Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method