Created
November 9, 2020 21:11
-
-
Save LGitHub-sprout/1fee46d29ff934cdf6d125aa99f6f37c to your computer and use it in GitHub Desktop.
if/else loop and sprintf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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