php入门变量之字符串,php入门变量
字符串只是一块用引号括起来的字符:字母、数字、空格、标点符号,等等。
下面列出的全都是字符串:
?1 2 3 4 |
'Huige'
"In watermelon sugar"
'100'
'August 2, 2011'
|
FAQ:
【1】在创建字符串时,可以使用单引号或双引号封装字符,此外,必须在字符的开头和末尾使用相同类型的引号。
【2】如果在字符串中间出现相同的引号,可以通过在有问题的字符(这里有问题的字符是双引号,以后还会了解到其他的有问题字符)前面放置一个反斜杠,它进行转义:
?1 2 3 |
<?php
$var = "Define \"platitude\", please." ;
?>
|
另一种方式是使用单引号(这种方式是在打印双引号时使用单引号,反之亦然):
?1 2 3 |
<?php
$var = 'Define "platitude", please.' ;
?>
|
【3】如果同一个变量赋值2次(比如:$book),新的值就会重写旧的值。
?1 2 3 4 |
<?php
$book = 'High Fidelity' ;
$book = 'The Corrections' ;
?>
|
结果自己打印下,这样就可以验证下是不是新的值重写旧的值。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

WebStorm Mac version
Useful JavaScript development tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft