PHP from scratch - Study Notes (a)

PHP

Power of PHP:
1, running on the server side: learn PHP, you can command your server to work, or even sabotage _ (do not really do it slightly), most of the data are stored in the WEB site the server side, PHP is used to process these data stored in the server (powerful it).

2, cross-platform: The server can be a variety of server platforms, such as Linux, Windows, Unix, you can command (do not be afraid it can only command a server-bar).

3, scripting language: it is by writing a script, that is, computer instructions line by line (also can be understood as a particular English word), to direct the server to work, therefore, in the process of writing PHP is actually the foreigner (server to foreigner friends) the process of communication, the language of communication is PHP.

4, free: free (world really have a free lunch).

start to learn

Write PHP code, write PHP code is very simple, is a single line of code. For example, look like this:

<?php
    echo"大家一起来学习PHP!";
?>

You can also write a line of code. Note: Single and double quotes can be.

<?php echo "大家一起来学习PHP!";?>
<?php echo '大家一起来学习PHP!';?>

Effect as
PHP code can be inserted the same as in HTML, JavaScript

<!DOCTYPE HTML>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>php语法</title>
    </head>
    <body>
        <p>
      <?php echo php代码;?>
        </p>
    </body>
</html>

However, note that the latter ?>may be omitted.
String: In PHP echo can be directly through the output string.

<?php echo "Hi php!";?>
//还可以这么连接两个字符串
<?php echo "Hi" . "php";?>

Can be done with PHP .(in English in the input period is - points) to connect the two strings. As well as the above code should see my comments, and for that double slash //This is the PHP in the comment character.
After the official start to understand the basis of the knowledge
variable
variable is used to store the value, the command server when we go to work, often need to generate some data, it requires a temporary storage for easy access. We can also be understood as variable like a shopping bag, we used to hold apple, durian (of course, can also be used to hold the rose), should be noted that, in general, a variable can only hold a (not greedy) value. Then take a look at how the code with a defined variables:

<?php
   $var = "欢迎来到我的博客:";
   echo $var;
   $var = "https://zxcv0221.github.io";
   echo $var;
?>

It can be seen variable names need to use "dollars" to identify, but also variable naming rules: the
Mu lesson taken from the network: a good place for self-study
type of data
PHP data type is also divided into: integer, floating point, string type, Boolean data type, etc. Different types accounted for "site" is not the same. You can see the size of the data space occupied by such a function.

<?php 
echo $m1 = memory_get_usage(); 
echo "<br />";//这是换行符
$var_string="123";
echo $m2 = memory_get_usage()-$m1; 
echo "<br />";
$n=123;
echo $m3 = memory_get_usage()-$m1-$m2; 
echo "<br />";
$f=123.00;
echo $m4 = memory_get_usage()-$m1-$m2-$m3; 
echo "<br />";
?>

Here Insert Picture Description
The first line is then initialized memory consumed, the following words, is to share minus the initialized memory will be able to see the data share the memory.
Output data type:

<?php $string = "就是就是";
      var_dump($string);
      echo "<br />";
      $string = 9494;
      var_dump($string);
      echo "<br />"
?>

Here Insert Picture Description
Boolean type is

<?php 
    $man = "男";
	$flag = $man == "男";
	echo $flag;
	echo "<br />";
	var_dump($flag);
?>

Here Insert Picture Description
When determining whether or not to meet the conditions, he is to meet with the "true", with "false" if not satisfied. Note that when the output Boolean type with "echo" command, if it is "true" then the output is "1", "false" nothing is output.
Float

  1. Input formats can be normal,
    2. enter lowercase or uppercase E e scientific notation can be
    represented; the + -number of subtraction is not
    Here Insert Picture Description
    an integer: can octal, decimal, hexadecimal specified;
    String:
    if desired output double or single quotes how to do? There are two methods:
    1. single quotes nested double or double quotes nested in single quotation marks.
    2. Use the escape character \.
    Here Insert Picture Description
    When output, quotes encounter美元
<?php 
$love = "I love you!"; 
$string1 = "PHP,$love";
$string2 = 'PHP,$love';
echo $string1;
echo "<br />";
echo $string2;
?>

Here Insert Picture Description
Summary:
when enclosed in double quotes variable, the variable will be connected to the content of double quotes;

When single quotes contains variables, variables will be output as a character string.
Such as a long string output poem or song.
First, using a string that represents a delimiter (<<<), followed by a GOD after the identifier "<<<", then the character string, the identifier provided to the final end of the string.

<?php 
$string1=<<<GOD
我有一只小毛驴,我从来也不骑。
有一天我心血来潮,骑着去赶集。
我手里拿着小皮鞭,我心里正得意。
不知怎么哗啦啦啦啦,我摔了一身泥.
GOD;

echo $string1;
?>

Identifier can be used casually, just a word or letter can ensure consistency on OK and forth. In addition to the end of the row identifiers and ;can not have other symbols, spaces, too.
Special Type:
NULL (NULL): NULL is an empty type, not case sensitive, NULL type only a value that represents a variable has no value, is assigned when a NULL, or has not been assigned, or is unset (), which three cases are considered variable to NULL.

<?php 
 error_reporting(0); //禁止显示PHP警告提示
 $var;
 var_dump($var);
 $var1=null;
 var_dump($var1);
 $var2=NULL;
 var_dump( $var2);
 $var3 = "节日快乐!";
 unset($var3);
 var_dump($var3);
?>

unset()Functions can be released after the variable is assigned. After releasing just did not assign the same variable. Type becomes NULL.
Notes just to be summed up their knowledge learned, later convenience. Learning, then it is recommended Mu lesson learning network.

Published 26 original articles · won praise 12 · views 3227

Guess you like

Origin blog.csdn.net/qq_45836474/article/details/104830572