Search
 
SCRIPT & CODE EXAMPLE
 

PHP

expresions

Note that even though PHP borrows large portions of its syntax from C, the ',' is treated quite differently. It's not possible to create combined expressions in PHP using the comma-operator that C has, except in for() loops.

Example (parse error):

<?php

$a = 2, $b = 4;

echo $a."
";
echo $b."
";

?>

Example (works):
<?php

for ($a = 2, $b = 4; $a < 3; $a++)
{
  echo $a."
";
  echo $b."
";
}

?>

This is because PHP doesn't actually have a proper comma-operator, it's only supported as syntactic sugar in for() loop headers. In C, it would have been perfectly legitimate to have this:

int f()
{
  int a, b;
  a = 2, b = 4;

  return a;
}

or even this:

int g()
{
  int a, b;
  a = (2, b = 4);

  return a;
}

In f(), a would have been set to 2, and b would have been set to 4.
In g(), (2, b = 4) would be a single expression which evaluates to 4, so both a and b would have been set to 4.
Comment

PREVIOUS NEXT
Code Example
Php :: laravel where has relation 
Php :: laravel eloquent where date today 
Php :: php foreach show only 4 
Php :: laravel model retrieve 
Php :: refresh database tables yii 1 
Php :: php season calculation 
Php :: add code return block phpstorm 
Php :: enfold remove debugging info for theme support 
Php :: most sites visited by ip address laravel 
Php :: php int to indonesian rupiah 
Php :: laravel pdf generator 
Php :: base64_decode 
Php :: php mailer 
Php :: hide .php 
Php :: how to implement email verification in laravel 
Php :: laravel collection unique 
Php :: doctrine findby criteria 
Php :: get action name in yii2 
Php :: unexpected end of file php 
Php :: php slow 
Java :: dependency for spring security 
Java :: how to set current date in android studio 
Java :: How do you nuke japan 
Java :: disable buttonjava 
Java :: how to clear the screen by pressing a key in java 
Java :: how to generate random numbers in java within range 
Java :: Thread inline ajva 
Java :: get tfidf score for a sentence 
Java :: Json web token dependency in Maven 
Java :: internet permission in android studio 
ADD CONTENT
Topic
Content
Source link
Name
6+4 =