Finally the environment is configured, try PHP!
Where should I write the code?
code ?>
<% code %>
Mark the author and make comments?
//author : matter
/*
*author : matter
*/
#author : matter
It finally officially started, ok, let’s go directly to the classic case
Pay attention to the discolored parts
Single quotes are OK, double quotes are also OK
Single quotes have incomplete support for escape characters!
Echo can be used, print can be used, and printf can also be used
Why do you add parentheses to printf?
The brackets for echo() and print() can be omitted
Is there a difference between echo and print?
echo() has no return value, print() successfully outputs and returns 1
So it can be seen that echo() is faster than print()!
Use printf for dynamic text, and echo
for static text.
$test=sprintf("$%.2f",12.3424);
printf("Goodbye-- World,$test");
sprintf can assign values to variables~
It’s time to show me variables!
Weakly typed language --- Everything is scalar
$myVar = "anything";
Array
$arr[0] = "abc";
It’s time to meet your partner!
class MyTest {
private $a;
public function getA() {
return $this->a;
}
public function setA($a) {
$this->a = $a;
}
}
$useage = new MyTest();
$useage->setA("HI~");
echo $useage->getA();
My own experience with JAVA
Function has no return type
Use "->" instead of "."
to call methods and properties
Regardless of whether it has been declared or not, always add $
in front of the variable.
I don’t know what type the variable is... What should I do?
Cast
(array)$sth
Automatic conversion
When calculating a string, take the previous number
The judgment condition of If() judges whether the calculation result is non-0
I want to have the right to know and control the variable type!
String Gettype( mixed var );
Return the type of variable var
Boolean settype( mixed var , string type )
Convert the type of variable
How big a part is the variable responsible for?
GLOBAL $var; //Global variable
STATIC $var; //Static variable
At present, only the keywords are different, the rest is normal
Super global variables---predefined, related to the environment
$_SERVER , $_GET , $_POST , $_COOKIE
$_FILES , $_ENV
When the variable remains unchanged~
Define("PI" , 3.1415);
Operator, operand, control statement
New:AND OR NOT XOR
No others found yet...
Excerpted from matter605924657