Php help

Place for questions and answers for all newcomers and new coders. This is a free for all forum, no question is too stupid and to noob.
Post Reply
shaints11
Posts: 10
Joined: Mon Dec 05, 2011 5:32 am

Php help

Post by shaints11 »

Ok, so I've been watching tutorials, following them, doing what callan s. , vint and halls have said but I've stumbled onto a question and now I have to ask

Can a variable be any name ? for example $anything $ok $cheese213.

My next question is, if statements, I'm trying my best to completely understand the concept of if statements so for what I'm seeing in if statements, is this viably ok? or is this completely wrong to think it this way

Code: Select all

if (this is correct) {

 echo 'Yes it'll run like that';
}
 else {
   echo 'No your answer to this is not correct or is half right';
}
And taking into consideration of what Halls, and Callan S. said, I've been timing myself on very very simple basic operations of php, and been improving my speed on those, and moving forth from their to more complex codes, or "bigger" Variables/arrays :p Slowly working my way up.
shaints11
Posts: 10
Joined: Mon Dec 05, 2011 5:32 am

Re: Php help

Post by shaints11 »

Nevermind, I answered my own questions going through a tutorial and doing a little sample to test my question

my example ;)

Code: Select all

 
<?php 

$number1 = 10;
$number2 = 11;
$number3 = 12;

if ($number1==12) {
  echo 'Equals 12';
} else if ($number2==12) {
  echo 'Equals 12';
} else if($number3==12){
   echo 'Equals 12';
} else {
 echo 'Not working';
}


?>
User avatar
vitinho444
Posts: 2825
Joined: Mon Mar 21, 2011 4:54 pm

Re: Php help

Post by vitinho444 »

Sorry for the delay, but let me explain it.
PHP thanks to the $ before the variable name doesn't have that much of a complication with variable names, but other languages (php is not excluded!) have reserved words for the programming itself, like int, bool, new, etc.

PHP has some but I think that if you name correctly your variables you won't have a problem.
Some good practice is to do something like:

Code: Select all

$var = 1;
$playerHealth = 100; //notice the capitalization
$player = new Player();
$enemy = new Enemy();
$enemyHealth = 200;
$enemy_health = 200; //is also a good practice to either use capitalization to separate words or "_" underscore.
About the if statements all you need to know (i think) is:

Code: Select all

if(true)
{
 echo "it's true";
}
else
{
 echo "it's false";
}
or

Code: Select all

if(playerHealth > 0)
{
 echo "Player is alive";
}
else if($playerHealth < 20)
{
echo "Player is bleeding";
}
else // $playerHealth >= 20
{
 echo "Player is fine";
}
That's basically what you need to know, also one more thing

Code: Select all

if(something)
{
 echo "something";
}
else if(hello)
{
 echo "the something is false!";
}
What i meant with this something code, is that whenever you pass the first "if" to the "else if", you can assume it turned false.
My Company Website: http://www.oryzhon.com

Skype: vpegas1234
Post Reply

Return to “Beginner Help and Support”