Sunday, 18 October 2015

#PHPro: Become a master in PHP

There is really no need in knowing what PHP stands for. You can google it if you want to know, you'll probably forget it.
We're here to learn how to master PHP in a month, start writing awesome code and building awesome apps.

***
FIRST STEPS
The learning process is similar for every programming language.

- Download your local server app (If you just try to run the php file, you'll look like an idiot)

- Set it up. I recommend XAMPP. Just google, you'll see it.

- Get a proper text editor. Notepad is for losers. Get something like Sublime Text, Brackets or conTEXT and you will code like a champ.

- GO AND LEARN HTML.
Seriously, if you're trying to learn PHP without HTML knowledge, what are you even doing on this planet??? Go and learn something else, like makeup art or something. Coding is not for you.

- Set goals: and do something every day. You need to make progress every day if you want to become a pro. Make sure you learn something daily. If you don't. your learning will be incomplete and you'll be unable to master the art.
I said so

- Practice: do I even have to say this? Your knowledge is no good without practice. What's the real reason you're learning? To make stuff right? So, use what you've learned to make stuff, play around, figure things out.

Important: Turn your knowledge into skill. If you don't, knowledge will just wash away.

PHP BASICS

The php tag.
It starts like this: <?php
ends like this: ?>
so it should look like this:
<?php
php code
php code
?>

Variables: are used to store values. You can call the variable later and use the value. Variables go like this... $name, with name being the name of the variable. They're declared like this:
 $name = "value";
Don't ever forget to close the line with the ";". Every line must end like that. If you don't close it, your whole code will just get screwed up.

You can also perform mathematical and logical operations using variables. E.g:

<?php
$number1 = 9;
$number2 = 5;

echo $number1 + $number2;
?>

The echo function: this is just used to make something show on the screen. E.g

echo "YO!";
You can also use HTML tags within an echo. E.g.

echo "<h1>YO!</h1>";

Arrays: These are just like variables, just that we can store multiple values in them,

$name = array(2,5,6,4,3);

You can call a value within an array by using the key selectors. Its simple, starting from 0, each element has a number as key. E.g. "6" in our little array, which is the third value, will have a key of 2. This is because, 2 will be 0, 5 will be 1.
Say, we want to call 4 which is the fourth element and we want it to appear on the screen.

echo $name[3];

However, when you have many values in an array, remembering the key number becomes difficult, hence the associative array becomes useful.

Associative array: its an array that lets you assign names to each value in an array, so you can easily call them later.

$numbers = array("first" => 10, "second" => 44);     And that's how you do it.

So let's try and call one of the numbers in our associative array.

echo $numbers[first];
That should bring the value named first on the screen.

***

That's all for today. Remember: Keep practicing, hone your skills and in one month, you'll be a badass PHP programmer. It's very important you know the basics. Don't jump into stuff you're not ready for and if you've done enough today, don't suffer your brain... let it chew on what you've learnt.
That's it on the first step of PHPro: Become a master in PHP

No comments:

Post a Comment