Skip to content

Instantly share code, notes, and snippets.

@houssemz
Last active June 28, 2018 09:39
Show Gist options
  • Save houssemz/6f06b847380a74faa46d9f462bd7c991 to your computer and use it in GitHub Desktop.
Save houssemz/6f06b847380a74faa46d9f462bd7c991 to your computer and use it in GitHub Desktop.

Post increment vs pre increment

<?php
$i = 10;
$a = $i++;
// Now $a is 10, and $i is 11

$i = 10;
$a = ++$i;
// Now $a is 11, and $i is 11

# There is sometimes a slight preformance cost for using $i++. See, when you do something like
$a = $i++; 

# You're really doing this:
$temporary_variable = $i;
$i = $i+1;
$a = $temporary_variable;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment