Reputation: 394
Is there a difference between this syntax of array?
coming from a dd()
$array:3 = [
0 => "email"
1 => " email"
2 => " email"
]
vs
$array = ['email', 'email', 'email']
I am doing this:
$email->bcc($bccEmailsArray);
which is the 1st code snippet, and it doesn't work. If I put in the 2nd code snippet, it works.
Upvotes: 0
Views: 85
Reputation: 12243
The main difference if fact that first sample is not valid PHP code.
Part array:3
makes it invalid.
Valid examples would be
$array = [
0 => "email",
1 => "email",
2 => "email"
];
and
$array = ['email', 'email', 'email'];
Beside the fact that in first example some "emails" start with space both arrays are equals. If you don't provide keys explicitly, elements will be numbered starting from 0.
For more info you can refer to documentation.
Upvotes: 0
Reputation: 7327
Like what others are saying your problem is just syntax. because of dd() it appears? dd() var_dump() etc are for debugging.
$array:3 = [ // :3 is not valid
0 => "email" //no commas
1 => " email" //no commas + extra spaces in emails
2 => " email" //no commas + extra spaces in emails
]
Correct it to :
$array = [
0 => "email",
1 => "email",
2 => "email",
]
or to either of these :
$array = [0=>"email",1 => "email",2 => "email"];
$array = array(0=>"email", 1=>"email", 2=>"email");
or just to:
$array = array("email","email","email");
as this will just produce default keys:
array(3) {
[0]=>
string(5) "email"
[1]=>
string(5) "email"
[2]=>
string(5) "email"
}
Hence there is no difference between the two if the syntax is correct.
More information:
Upvotes: 1