Difference between array() and [] in PHP Last Updated : 17 Jul, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report An array can be created using the array() language construct. It takes any number of comma-separated key => value pairs as arguments. Syntax: array( key => value, key2 => value2, key3 => value3, ... ) The comma after the last array element is not required can be omitted but this can help to understand other developers that the array is updated or not. This is usually done for single-line arrays, i.e. array(1, 2) is preferred over array(1, 2, ). For multiple line arrays, on the other hand, the trailing comma is commonly used, as it allows easier to add new elements at the end of the present array. Note: Only the difference in using [] or array() is with the version of PHP you are using. In PHP 5.4 you can also use the short array syntax, which replaces array() with []. Example: php <?php $array = array( "geek" => "tech", "tech" => "geek", ); var_dump($array); // As of 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" } Comment More infoAdvertise with us Next Article How to Iterate Over an Array in PHP? S SachinDiwakar1 Follow Improve Article Tags : Web Technologies PHP PHP Programs Similar Reads Difference between isset() and array_key_exists() Function in PHP isset() function The isset() function is an inbuilt function in PHP which checks whether a variable is set and is not NULL. This function also checks if a declared variable, array or array key has null value, if it does, isset() returns false, it returns true in all other possible cases. Syntax: boo 2 min read Different Ways to Delete an Item From an Array in PHP Given an array containing some elements, the task is to Delete an item from an array using PHP. Below are the approaches to delete an item from an Array in PHP: Table of Content Using unset() FunctionUsing array_splice() FunctionUsing array_diff() FunctionUsing array_filter() FunctionUsing array_sea 3 min read What is the difference between echo, print, and print_r in PHP? echo: echo is not a function rather it is described as a language construct. It accepts an list of argument (multiple arguments can be passed) and returns no value or returns void. It cannot be used as a variable function in PHP. It is used to display the output of parameters that is passed to it. I 2 min read How to Iterate Over an Array in PHP? Arrays are fundamental data structures in PHP, and the ability to iterate through them is crucial for manipulating and processing data. In this article, we will explore various approaches to iterate through arrays in PHP.Table of ContentUsing for LoopUsing foreach LoopUsing while Loop with each() Fu 3 min read How to get the First Element of an Array in PHP? Accessing the first element of an array in PHP is a common task, whether they are indexed, associative, or multidimensional. PHP provides various methods to achieve this, including direct indexing, and built-in functions.Below are the approaches to get the first element of an array in PHP:Table of C 4 min read Remove an Elements From End of an Array in PHP Given an array "myArray", the task is to remove an element from its end. This operation is important in scenarios involving stacks, queues, and web development. In PHP, there are several approaches to achieve this One common method is using the array_pop() function, which removes the last element fr 3 min read Like