Skip to content

Instantly share code, notes, and snippets.

@yetimdasturchi
Created March 25, 2023 23:40
Show Gist options
  • Save yetimdasturchi/0b16eaf67a5054f061166824829034d8 to your computer and use it in GitHub Desktop.
Save yetimdasturchi/0b16eaf67a5054f061166824829034d8 to your computer and use it in GitHub Desktop.
Codesample for explain pre and post increments
<?php
function pre( &$y ) {
$y = $y + 1;
return $y;
}
function post( &$y ) {
$old = $y;
$y = $y + 1;
return $old;
}
$x=1; printf(
"Pre:\n\tKirish: %d\n\tChiqish: %d\n",
pre( $x ),
$x
);
$x=1; printf(
"Post:\n\tKirish: %d\n\tChiqish: %d\n",
post( $x ),
$x
);
/*
Pre:
Kirish: 2
Chiqish: 2
Post:
Kirish: 1
Chiqish: 2
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment