[ad_1]
Facebook –
GitHub –
Google+ –
LinkedIn –
reddit –
Support –
thenewboston –
Twitter –
Beginner PHP Tutorial – 192 – Changing a Property Value
by
Tags:
Comments
19 responses to “Beginner PHP Tutorial – 192 – Changing a Property Value”
-
Thank you so much, Alex<3.
-
I'm sorry if this question is stupid, I'm just a beginner. Where did you declare a value of $amount?
-
i cant get code when a value has manually been put in by the coder… i need to know how this works with a database.
-
6:51 "we have created a new method called Withdraw" So it's a method and not a function? Part of my research, which has brought me to these videoes (190-192), was to investigate PHP methods and functions…or 'what is the difference between them. i read here http://stackoverflow.com/questions/4841605/what-is-a-difference-between-a-method-and-a-function that "Method is actually a function used in the context of a class/object." Is it incorrect to use the terms interchangeably? Thanks
-
example for this lesson 🙂
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
margin: 0;
}
</style>
</head>
<body>
<form action="<?= $_SERVER['PHP_SELF']; ?>" method="POST" name="form">
<input type="number" name="amount"/>
<input type="submit" name="submit" value="WITHDRAW"/>
</form>
<?php
if(isset($_POST['amount']) && !empty($_POST['amount'])){
$amount=$_POST['amount'];
class BankAccount{
public $balance=100;
public function Withdraw($amount) {
if($this->balance>$amount){
$this->balance= $this->balance-$amount;
echo "Withdrwan: ".$amount."<br>";
return "Balance: ".$this->balance;
}
else{
die("Sorry, insufficient funds");
}
}
}
$account=new BankAccount;
echo $account->Withdraw($amount);
}
?>
</body>
</html> -
Ok, question time. Cant you do this with function Withdraw? function Withdraw($balance, $amount)? // queried result
$balance = 100;function Withdraw($balance, $amount)
{
if($amount > $balance)
{
return "No enough money";
}else
{
return $balance – $amount;}
}echo $alex = Withdraw($balance, 15);
echo "<br>";
echo $john = Withdraw($balance, 150);Or am i missing something?
-
HEADS UP: The tutorials are a bit out of order. After this video, you are going to want to watch 196-198 before continuing to 193.
-
whithdrawwwwwwwwwwwwww
-
where were the constructor is public function __construct() mandatory to get data from a class.?
-
nice tutorial, could add a thing about encapsulation 😉
-
Thank you for the great Tutorials.
-
$newamount = intval($amount);
-
and what if $amount is negative number? like -100000000 ?
-
I appreciate the effort you've made, but as this is a tutorial for beginners, and the concepts are new and quite complex from a learners perspective, it would help if you could edit out the mistakes so I can focus on the right way to do things.
-
hey alex, you made this tutorial easy like anything, Nice tutorial 🙂
-
lol where it is written that it is pounds? It can be $, euro or rupees
-
Look, the troll is gone. No dislikes!
-
@bohterham if you mean return $this->balance -= $amount; yes, it is valid and working. the shortcut for return $this->balance = $this->balance – $amount;
-
is $this->balance =- $amount; valid?
Leave a Reply