PHP Lesson 2 – Variables
The variable In its simplest definition, they're structures used to store data we want. You can compare them to an empty glass. We can pour whatever we want into it.
PHP'also those who change names $ It starts with a sign. Turkish characters, spaces, dashes in the name (-), we cannot use special characters. For example variable Let's define;
<?php $isim = "Erhan"; $yer = "Türkiye"; $tam_isim ="Erhan Kılıç"; $isim = $tam_isim; $yil = 2015; ?> <!DOCTYPE html> <html> <head> <title>Erhan Kılıç</title> </head <body> <h1><?php echo $isim ?></h1> <h3>Location:</h3> </body> </html>
PHPat the end of our codes (;) We put a ' ' sign. This indicates that the code ends on that line. Of course, we can write different codes on the same line. As seen in our example variables We can define them however we want. We can equate them to each other. When defining numbers, nail We don't need the ' ' symbol. I'll explain data types in our next lesson. We'll go into more detail then.
As we write code and our work grows, we can write comments to help us remember what code we wrote for what purpose and to make it easier for others to read. PHP are texts that are skipped by the interpreter. PHP Even if it's code, it will be ignored. For example, let's write code that's a comment:
<?php // Bu benim ismim. $isim = "Erhan"; // $yer = "Türkiye"; /* Yer: Türkiye bla bla bla */ $tam_isim ="Erhan Kılıç"; $isim = $tam_isim; ?>
To comment a single line, add it to the beginning (//) It is enough to put. To comment more than one line, either at the beginning of each line (//) We should put it or apply an easier method. (/*) sign, at the end of (*/) We put a sign.
PHPThe way it works is from top to bottom. That is, there is a variable after giving the value we give another value below, variable The final content is the value we specify below. However, the first value is valid up to the line where we specify that value.
PHPIn , spaces between lines are also ignored. That is, spaces between two lines PHP It doesn't mean anything to you. But as follows: variable The same does not apply to spaces in definitions.
<?php $degisken = " Merhaba "; ?>