github初学者指南_2020年面向初学者的终极PHP指南

github初学者指南

重点 (Top highlight)

PHP is a server scripting language and a tool for making dynamic and interactive websites. Before you get into learning PHP, you’ll need a little HTML, CSS, and JavaScript. To this end, I wanted to put together an article the shared an overview of learning PHP in the hopes that it might help beginners gain a foothold in the world of PHP.

PHP是一种服务器脚本语言,并且是制作动态和交互式网站的工具。 在学习PHP之前,您需要一些HTML,CSS和JavaScript。 为此,我想发表一篇文章,分享学习PHP的概述,以期帮助初学者在PHP领域立足。

什么是PHP? (What is PHP?)

PHP is an acronym for “PHP: Hypertext Preprocessor” and can run on a webserver

PHP是“ PHP:超文本预处理器”的缩写,可以在Web服务器上运行

如何安装PHP (How to install PHP)

You can download the virtual environment called XAMP on this link.

您可以在此链接上下载名为XAMP的虚拟环境。

PHP语法 (PHP Syntax)

A PHP script can be placed anywhere in a PHP file as long as it looks like this:

只要如下所示,PHP脚本就可以放置在PHP文件中的任何位置:

<?php //Scripts go here?>

You can save a PHP file as FileName.php

您可以将PHP文件另存为FileName.php

注释 (Comments)

In Php, you can create a comment by using double slashes (as in the script above).

在Php中,您可以使用双斜杠创建注释(如上面的脚本中所示)。

PHP中的变量 (Variables in PHP)

In PHP, all variables start with a dollar sign followed by the name of the variable. If you want to assign a value to the variable you can do it as shown below:

在PHP中,所有变量均以美元符号开头,后跟变量名称。 如果要给变量赋值,可以如下所示:

<?php  $variable_1 = 1;
$greeting = "Hello World";?

If you want to concatenate two variables, you can do this by using the ‘.’

如果要串联两个变量,可以使用“。”来实现。

<?php$var1 = "Hello";
$var2 = "World";$var3 = $var1 . $var2;echo $var3;//Will output: Hello World?>

If you want to add two numbers, you need to use ‘+’ if you use ‘’ you will end up with the two numbers next to each other.

如果要添加两个数字,则使用'+',如果使用'',则最后两个数字彼此相邻。

输出文字 (Output text)

In PHP, you can use either an ‘Echo’ statement or a ‘Print’ statement. Examples of Echo and Print statements can be seen below:

在PHP中,您可以使用“ Echo”语句或“ Print”语句。 下面是Echo和Print语句的示例:

<?php $var = "Hello World";echo $var;//Output will be: Hello World!print $var;//Output will be: Hello World?>

资料类型 (Data Types)

In programming, a variable has a data type; in PHP, these are the most common data types:

在编程中,变量具有数据类型。 在PHP中,这些是最常见的数据类型:

  • String — A sequence of characters

    String —字符序列
  • Integer — An integer data type is a non-decimal number

    整数—整数数据类型是非十进制数
  • Float — A float is a number with a decimal point or a number

    浮点数—浮点数是带有小数点或数字的数字
  • Boolean — A Boolean represents TRUE or FALSE.

    布尔值—布尔值表示TRUE或FALSE。
  • Array — An array stores multiple values in one single variable.

    数组—数组将多个值存储在一个变量中。

PHP中的数学 (Math in PHP)

PHP has a couple of mathematical functions like ‘pi()’ that returns the value of pi.

PHP具有一些数学函数,例如“ pi()”,它们返回pi的值。

Pi()

Pi()

<?php echo pi(); ?>

Min() & Max()

最小()和最大()

Or the functions ‘min()’ and ‘max()’ to calculate the largest and the smallest number is a sequence.

或用于计算最大和最小数字的函数'min()'和'max()'是一个序列。

<?php echo min(5,12,42,414,224);//will output: 5echo max(5,12,42,414,224);//will output: 414?>

Abs()

Abs()

With ‘abs()’ you can return the absolute value of a number:

使用“ abs()”,您可以返回数字的绝对值:

<?php echo abs(-5.5); ?> // will output 5.5

Sqrt()

Sqrt()

With ‘Sqrt()‘ you can return the Square Root of a number:

使用“ Sqrt()”,您可以返回数字的平方根:

<?php echo sqrt(16); ?> // will output 4

Round()

回合()

The ‘Round()’ function rounds a float number:

'Round()'函数舍入一个浮点数:

<?php echo round(2.2); ?> // will output 2

Rand()

兰德()

The last function is the ‘Rand()’ function that returns a random number:

最后一个函数是“ Rand()”函数,该函数返回一个随机数:

<?php echo rand(); ?> // will output a random integer

基本运算符 (Basic Operators)

  • + (Addition)

    +(加法)
  • - (Subtraction)

    -(减法)
  • * (Multiplication)

    *(乘法)
  • / (Division)

    /(部门)
  • % (Modules)

    %(模组)
  • ** (Exponentiation)

    **(幂)

陈述 (Statements)

In PHP, there are many different statements just as in any other programming language, and I’ll show them to you.

在PHP中,与其他任何编程语言一样,有许多不同的语句,我将向您展示。

如果{else}语句 (If { else } statement)

An “if else” statement or a “conditional statement” is used to act at the moment, and the result is true.

此刻使用“ if else”语句或“条件语句”执行,结果为真。

if (condition) {
code to be executed if condition is true
;
} elseif(second condition) { code to be executed if second condition is true;
else { code to be executed if condition is false;}

切换语句 (Switch Statement)

You can use the switch statement to act when you have a lot of conditions that you need to check.

当您需要检查许多条件时,可以使用switch语句执行操作。

switch (n) {
case label1: code to be executed if n=label1;
break;
case label2: code to be executed if n=label2;
break;
case label3: code to be executed if n=label3;
break;
...
default: code to be executed if n is different from all labels;
}

循环 (Loops)

If you want your code to run repeatedly until it has reached a specific condition then you might want to use a loop.

如果要让代码重复运行直到达到特定条件,则可能要使用循环。

While循环 (While loop)

A while loop runs over a particular block of code as long as the condition is true.

只要条件为真,while循环就会在特定的代码块上运行。

while(1+1 == 2){
echo "1 + 1 = 2";
}

对于循环 (For Loop)

A “for” loop walks over a block of code a certain number of times.

“ for”循环遍历一段代码一定次数。

for (init counter; test counter; increment counter) {code to be executed for each iteration;
}

What do all these terms mean? Well, the init counter is the initialization of a variable to act as an index number. The test counter is the condition, and the increment counter makes sure that the index gets incremented every time the code runs.

所有这些术语是什么意思? 好吧,init计数器是变量的初始化,用作索引号。 测试计数器是条件,递增计数器确保每次代码运行时索引都会递增。

<?php
for ($x = 0; $x <= 10; $x++) {
echo "$x <br>";
}
?>

This code will display number 0–10 with line breaks.

该代码将显示带换行符的数字0-10。

For-Each loop

每次循环

The “for-each” loop Loops through a block of code for each element in an array.

“ for-each”循环遍历数组中每个元素的代码块。

foreach ($array as $value) {code to be executed;
}

数组 (Arrays)

An array in PHP is nothing more than a list containing multiple variables as follows:

PHP中的数组不过是包含多个变量的列表,如下所示:

<?php
$cars = array("Ford", "Tesla", "Audi");
?>

With the for-each loop, you can run over the array and display every single item in it.

使用for-each循环,您可以在数组上运行并显示其中的每个项目。

$cars = array("Ford", "Tesla", "Audi");foreach ($cars as $car) {
echo "$car<br>";
}

功能 (Functions)

Besides the built-in PHP functions, it is possible to create your own functions.

除了内置PHP函数之外,还可以创建自己的函数。

function functionName() {  code to be executed;
}

Make sure that your function name is clear, and everybody understands it, including yourself.

确保您的函数名称清晰明了,包括您自己在内的每个人都可以理解。

<?php
function writeMsg() {
echo "Hello Medium!";
}
writeMsg(); // call the function
?>

结论 (Conclusion)

PHP can be an incredibly handy and versatile tool in your programming toolbox, allowing you to develop websites that stand out from the pack. Coming to terms with a new language can be daunting but by developing your skillset incrementally you’ll be surprised by how quickly you can progress. I hope that this article can act as a helpful stepping stone on your journey to becoming familiar with PHP, at the very least I hope that it has piqued your interest!

PHP可以在您的编程工具箱中成为非常方便和多功能的工具,使您可以开发脱颖而出的网站。 掌握一种新语言可能会令人望而生畏,但通过逐步发展技能,您会对进步的速度感到惊讶。 我希望本文可以成为您熟悉PHP的有用的垫脚石,至少我希望它引起了您的兴趣!

翻译自: https://levelup.gitconnected.com/the-ultimate-php-guide-for-beginners-in-2020-bf9de76a2e61

github初学者指南

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值