[php learning 2] Basic grammar exercises 1
Since the results are almost filling one page, let’s record them first~!
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>First Php</title> </head> <body> <h1>三好少年</h1> <?php /*基本语法练习 *1,定义变量必须加$,但不用写类型.这就导致了定义和赋值是一样的语句了. */ $x = 5; $y = 10; function Test(){ global $x , $y;/*访问全局变量必须加GLOBAL*/ static $z = 0;/*静态局部变量*/ $y = $y + $z; $z++; } Test(); Test(); echo $y,'<br>';//11 /* * 1,echo没有返回值,可以输出多个字符串,逗号隔开~ * 2,Print总返回1,只能输出一个字符串~ * 3,单引号只能输出字符串,双引号能输出变量~ * 4,var_dump这个犀利啊,能监测变量类型,并输出值. * 5,数组元素可以不同类型,这个语法也是没谁了. */ $cars = array("Volvo","BMW","TOYOTA",5); echo "字符串1","字符串2",'字符串3'; echo '<h2>PHP IS Fun</h2>';//还能输出标签~ echo "$cars[0]<br>"; print("print只能一个字符串<br>"); print("print也能输出标签<h2>print标签</h2>"); var_dump($cars); print '<br>'; /* * 1,常量的定义真不怎么样,默认区分大小写,想不区分的话,最后参数为False; * 2,print(china_display + constInt + '<br>');这个有错误,但能运行,只显示800;看来这个编译器不是很严格.~ * 3,常量默认全局的,函数调用的话不用Global修饰; * */ define("china_display","中华人民共和国"); define("constInt",800); echo china_display,constInt,'<br>'; function TestConst($a){ echo china_display, $a, '<br>'; } TestConst("伟大"); /* * 1,两个字符串链接有个叫"并置运算符"用.标示,链接两个字符串.~ * 2,strlen对于汉字的输出是n*3,不是n*2; */ $txt1 = '字符串第一部分'; $txt2 = '字符串第二部分'; print $txt1 . $txt2 .'<br>'; echo 'abc 长度',strlen("abc"),";","你好么 长度",strlen("你好么"), "<br>"; echo 'abc b的位置',strpos("abc","b"),";","你好么 好的位置",strpos("你好么","好") ,"<br>"; /* * 1,比较运算符中,==和===是两码事,==纯粹的比较,====加上了类型的判断. * 2,echo false什么也不输出; * 3,isset()如果变量未设置或者为NULL,则返回False,否则True;挺重要的函数啊~; * 4,empty()如果变量不存在或其值为""、0、"0"、NULL、、FALSE、array()、var $var; 以及没有任何属性的对象,则返回True,否则False; * */ $int100 = 100; $str100 = '100'; function BoolToStr($A){ if ($A === true){ return "True"; } else{ return "False"; } } echo BoolToStr($int100 == $str100) , ",", BoolToStr($int100 === $str100),"<br>";//true,false $ussername = true?"0":"hello"; print BoolToStr(isset($ussername)) . '<br>';//True print BoolToStr(empty($ussername)) . '<br>';//True /* * 1,switch也支持字符串; * 2,没有Default也不抱错. * */ $favcolor="red"; switch ($favcolor) { case "red": echo "你喜欢的颜色是红色!"; break; case "blue": echo "你喜欢的颜色是蓝色!"; break; case "green": echo "你喜欢的颜色是绿色!"; break; default: echo "你喜欢的颜色不是 红, 蓝, 或绿色!"; } /* * 1,count能计算出数组长度,这中写法有点LOW,早晚写个全局类来替代它. * 2,Count对字符串无效,结果为1; * 3,关联数组的类型也是混着都可以.前面是索引,后面是值,所以这类数组只能Foreach遍历; * */ echo "Cars数量:",count($cars),'<br>';//4 echo count("aaaaddd"),'<br>';//1 for ($x = 0; $x < count($cars); $x ++) { echo $cars[$x], '<br>'; } foreach($cars as $x){ echo $x, '<br>'; } $ages = array('梅西'=>29, "C罗"=>'31',5=>8); foreach($ages as $x => $x_value){ echo "name:",$x,"age:",$x_value,'<br>'; } echo $ages["C罗"]; ?> </body> </html> <?php ?>
The above introduces [php learning 2] basic grammar exercise 1, including aspects of content. I hope it will be helpful to friends who are interested in PHP tutorials.

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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Many users will choose the Huawei brand when choosing smart watches. Among them, Huawei GT3pro and GT4 are very popular choices. Many users are curious about the difference between Huawei GT3pro and GT4. Let’s introduce the two to you. . What are the differences between Huawei GT3pro and GT4? 1. Appearance GT4: 46mm and 41mm, the material is glass mirror + stainless steel body + high-resolution fiber back shell. GT3pro: 46.6mm and 42.9mm, the material is sapphire glass + titanium body/ceramic body + ceramic back shell 2. Healthy GT4: Using the latest Huawei Truseen5.5+ algorithm, the results will be more accurate. GT3pro: Added ECG electrocardiogram and blood vessel and safety

Why Snipping Tool Not Working on Windows 11 Understanding the root cause of the problem can help find the right solution. Here are the top reasons why the Snipping Tool might not be working properly: Focus Assistant is On: This prevents the Snipping Tool from opening. Corrupted application: If the snipping tool crashes on launch, it might be corrupted. Outdated graphics drivers: Incompatible drivers may interfere with the snipping tool. Interference from other applications: Other running applications may conflict with the Snipping Tool. Certificate has expired: An error during the upgrade process may cause this issu simple solution. These are suitable for most users and do not require any special technical knowledge. 1. Update Windows and Microsoft Store apps

In today's era of rapid technological development, programming languages are springing up like mushrooms after a rain. One of the languages that has attracted much attention is the Go language, which is loved by many developers for its simplicity, efficiency, concurrency safety and other features. The Go language is known for its strong ecosystem with many excellent open source projects. This article will introduce five selected Go language open source projects and lead readers to explore the world of Go language open source projects. KubernetesKubernetes is an open source container orchestration engine for automated

"Go Language Development Essentials: 5 Popular Framework Recommendations" As a fast and efficient programming language, Go language is favored by more and more developers. In order to improve development efficiency and optimize code structure, many developers choose to use frameworks to quickly build applications. In the world of Go language, there are many excellent frameworks to choose from. This article will introduce 5 popular Go language frameworks and provide specific code examples to help readers better understand and use these frameworks. 1.GinGin is a lightweight web framework with fast

Laravel is a popular PHP framework that is highly scalable and efficient. It provides many powerful tools and libraries that allow developers to quickly build high-quality web applications. Among them, LaravelEcho and Pusher are two very important tools through which WebSockets communication can be easily implemented. This article will detail how to use these two tools in Laravel applications. What are WebSockets? WebSockets

Detailed explanation of the role and usage of the echo keyword in PHP PHP is a widely used server-side scripting language, which is widely used in web development. The echo keyword is a method used to output content in PHP. This article will introduce in detail the function and use of the echo keyword. Function: The main function of the echo keyword is to output content to the browser. In web development, we need to dynamically present data to the front-end page. At this time, we can use the echo keyword to output the data to the page. e

Part 1: Initial Troubleshooting Steps Checking Apple’s System Status: Before delving into complex solutions, let’s start with the basics. The problem may not lie with your device; Apple's servers may be down. Visit Apple's System Status page to see if the AppStore is working properly. If there's a problem, all you can do is wait for Apple to fix it. Check your internet connection: Make sure you have a stable internet connection as the "Unable to connect to AppStore" issue can sometimes be attributed to a poor connection. Try switching between Wi-Fi and mobile data or resetting network settings (General > Reset > Reset Network Settings > Settings). Update your iOS version:

php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code
