Comma isn’t a concatenator. it use for printing or rather echoing a list of variable, string and numbers similar to how it is used in English. While dot joins two strings together to make one longer string.
Take note: comma only work when using the echo language construct and you can’t return a comma delimited variable.
Examples
Let’s see some code example.
- 1234
<?php
$a
=
'i am'
;
$b
=
' boy'
;
echo
$a
,
$b
;
12345<?php
$a
=
'i am'
;
$b
=
' boy'
;
$c
=
$a
.
$b
;
echo
$c
;
1234<?php
$a
=
'i am'
;
$b
=
' boy'
;
echo
$a
.
$b
;
Result: i am boy - 1234
<?php
$a
=
'i am'
;
$b
=
' boy'
;
print
(
$a
,
$b
);
1234<?php
$a
=
'i am'
;
$b
=
' boy'
;
$c
=
$a
,
$b
;
1234<?php
$a
=
'i am'
;
$b
=
' boy'
;
return
$a
,
$b
;
Result: Parse error: syntax error, unexpected ‘,’ in C:\xampp\htdocs\index.php on line 4
It is worth noting that when using echo, delimiting string with comma is faster than dot.
0 comments:
Post a Comment