The dot in PHP is used for object and array access, and commas are used to separate variable lists, array values, and function parameters.
The difference between dot (.) and comma (,) in PHP
In PHP, dot (.) and comma (,) are two different operators with different purposes.
Dot (.)
<code class="php">$user = new User(); $name = $user->name;</code>
<code class="php">$array = ['name' => 'John', 'age' => 30]; $name = $array['name'];</code>
Comma (,)
<code class="php">function sum(int $a, int $b) { return $a + $b; }</code>
<code class="php">$array = [1, 2, 3];</code>
<code class="php">echo print_r($array, true);</code>
Summary
The period (.) in PHP is mainly used for object and array access, while the comma (,) is mainly used for separation Variable lists, array values, and function parameters.
The above is the detailed content of What is the difference between dot and comma in php. For more information, please follow other related articles on the PHP Chinese website!