This question already has answers here:
PHP array vs [ ] in method and variable declaration
(5 answers)
PHP: What's the difference between initializing an array with "new" vs without it?
(4 answers)
Closed 1 year ago.
What is the difference between declaring:
$myArray = Array();
and:
$myArray = [];
There's no difference, it's just two alternative syntaxes. See https://www.php.net/manual/en/language.types.array.php
Related
This question already has answers here:
PHP Difference between array() and []
(5 answers)
Closed 9 months ago.
I want to know if there's any difference in either the output or the object being created when these commands are run to create the object $array.
$array = ["Sagittarius", "Cancer", "Gemini", "Pisces"];
$array = array("Sagittarius", "Cancer", "Gemini", "Pisces");
Thanks for the feedback!!
They are the same but [] is the shortened version introduced in PHP 5.4.0.
http://docs.php.net/manual/en/language.types.array.php
This question already has answers here:
Best way to initialize (empty) array in PHP
(9 answers)
Reference Guide: What does this symbol mean in PHP? (PHP Syntax)
(24 answers)
PHP Difference between array() and []
(5 answers)
Closed 3 years ago.
in evey tutorial they said you should make an array with "array()" but I realize that I can also make it with "[]" what are the difference?
array() :
$a = array("red","blue","green");
[] :
$a = ["red","blue","green"];
This question already has answers here:
How to add elements to an empty array in PHP?
(8 answers)
Closed 5 years ago.
Given this PHP array:
$options['systems'] = array(1, 2, 3)
How would I append the value 4 to the $systems array within the $options array?
You could use array_push to push additional items like so:
array_push($options['systems'], 4);
Or the shorthand version:
$options['systems'][] = 4;
You can use php array_push function. Like this. array_push($options['systems'],4);
you can read the detail of array_push from below link.array_push manual
This question already has answers here:
Reference Guide: What does this symbol mean in PHP? (PHP Syntax)
(24 answers)
Closed 6 years ago.
Is foo[] an array?
In the following code is an array element being assigned to foo[]? And is there an array key that is automatically associated with it?
$this->foo[] = 'hello world';
This is adding an element to the end of the foo array.
It's the same as using array_push().
This question already has answers here:
Parse query string into an array
(12 answers)
Closed 8 years ago.
My chain in PHP is like the following:
$chain = "m=toto&i=12&a=new";
How to get m, i and a values ?
Thanks.
Try This:
<?php
$chain = "m=toto&i=12&a=new";
parse_str($chain,$array);
This will create an array named $array containing all values you can access them as $array['m']
You can Print all this by:
print_r($array);