What is the difference between dot and comma in php

下次还敢
Release: 2024-04-29 10:30:20
Original
1132 people have browsed it

The dot in PHP is used for object and array access, and commas are used to separate variable lists, array values, and function parameters.

What is the difference between dot and comma in php

The difference between dot (.) and comma (,) in PHP

In PHP, dot (.) and comma (,) are two different operators with different purposes.

Dot (.)

  • Object access operator: Used to access properties or methods in an object. For example:
<code class="php">$user = new User();
$name = $user->name;</code>
Copy after login
  • Array key access operator: is used to access values ​​in an array. For example:
<code class="php">$array = ['name' => 'John', 'age' => 30];
$name = $array['name'];</code>
Copy after login

Comma (,)

  • Variable list separator: is used to separate variable lists, such as functions parameters or array elements. For example:
<code class="php">function sum(int $a, int $b) {
    return $a + $b;
}</code>
Copy after login
  • Array value separator: is used to separate values ​​in an array. For example:
<code class="php">$array = [1, 2, 3];</code>
Copy after login
  • Function call delimiter: is used to separate parameters of function calls. For example:
<code class="php">echo print_r($array, true);</code>
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!