Skip to content

Instantly share code, notes, and snippets.

@LGitHub-sprout
Created November 9, 2020 21:11
Show Gist options
  • Save LGitHub-sprout/1fee46d29ff934cdf6d125aa99f6f37c to your computer and use it in GitHub Desktop.
Save LGitHub-sprout/1fee46d29ff934cdf6d125aa99f6f37c to your computer and use it in GitHub Desktop.
if/else loop and sprintf
function bank_balance( $checking_balance ) {
$savings_balance = 100;
if ( $checking_balance < 100 ) {
$money = 1000;
$checking_balance += $money;
} else {
$savings_balance += 50;
$checking_balance -= 50;
}
// return sprintf( '<p>Savings Balance: %s</p><p>Checking Balance: %s',
// $savings_balance, $checking_balance );
printf( '<p>Savings Balance: %s</p><p>Checking Balance: %s',
$savings_balance, $checking_balance );
}
// return sprintf inside function and echo when calling function
// https://www.php.net/manual/en/function.sprintf.php
// echo bank_balance( 99 );
// can simply call function using printf since it outputs the string
// https://www.php.net/manual/en/function.printf
bank_balance( 69 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment