php学习笔记(一)
1.执行运算符是反引号 (``), 相当于 shell_exec() 函数,执行一个系统命令 $out=`dir`;//列出当前的目录和文件信息 2.定义常量 define(str,this is a const variableBR);echo str; 3.字符串 用单引号或双引号括起来。区别是在双引号中出现变量时会替换为变量
1.执行运算符是反引号(``),相当于shell_exec()函数,执行一个系统命令
$out=`dir`;//列出当前的目录和文件信息
2.定义常量
define("str","this is a const variable<br>"); echo str;
3.字符串
用单引号或双引号括起来。区别是在双引号中出现变量时会替换为变量的值。
$a=10; echo("variable is $a"); echo('variable is $a'); //结果为:variable is 10variable is $a
4、接受数据
使用变量$_POST读取表单数据。如果控件的name属性为c1,则用下面的方式获取他的值:
$_POST[`c1`]
Index.php文件
ShowInfo.php文件
if(isset($_POST['submit']) && $_POST['submit']){ echo("<br>用户名:".$_POST['username']."<br>"); }
5、接受网址中的参数信息
在网址中传递参数,格式为:
http://网址/网页文件?参数1>=
接受参数:使用变量:$_GET['参数名']
<a href="ShowInfo.php?name=Johney&sex=man">submit</a> ShowInfo.php文件 echo ("name: ".$_GET['name']."<br>"); echo ("sex: ".$_GET['sex']);
6、定义数组
array([key=>]value
,...
)
关键字可以是整数和字符串。关键字省略后以下一个数字为关键字,从0开始。
$arr=array("first"=>"Cpu","disk",2=>"memory","screen"); print_r($arr); //结果: Array ( [first] => Cpu [0] => disk [2] => memory [3] => screen )
多维数组
$arr[0][0]="CPU"; $arr[2][3]="memory"; print_r($arr); //结果: Array ( [0] => Array ( [0] => CPU ) [2] => Array ( [3] => memory ) )
7、数组函数
print_r($arr);//输出数组
$tmp=array_change_key_case($arr,CASE_LOWER);//OR CASE_UPPER
返回字符串关键字名全为小写或大写的数组
$tmp=array_count_values($arr);
统计数组中所有value出现的次数,结果返回到另一个数组中
array_fill:使用指定的值填充数组
array_fill(int start_index, int num, value);
$arr=array_fill(2,2,"element"); print_r($arr); 结果为:Array ( [2] => element [3] => element )
bool array_key_exists(key, $arr);//检查数组中指定的关键字是否存在
$tmp=array_keys($arr [,value]);//返回一个数组,列出所有关键字;若指定value,则只返回值为value的关键字
$tmp=array_merge($arr1,$arr2,...);//将多个数组合并,若关键字相同,前面的将被覆盖
array_pop($arr);//将数组的最后一个元素弹出
array_push($arr,value1,value2,...);//将多个元素压入数组尾部,数字作为关键字
array_reverse($arr);//数组反序排列
$tmp=array_sum($arr);//元素求和
array_unique($arr);//删除数组中重复的元素
arsort($arr);//降序排序
asort($arr);//升序排序
8、遍历数组
$arr=array('a'=>'a','b'=>'b','c'=>'c',"CPU","memory",'4'); foreach($arr as $val){ echo $val." "; } //OR: for($i=0;$i<sizeof echo current next><br> <p><span>两种方法效果相同,结果为:a b c CPU memory 4 </span></p> <p><span><strong>sizeof($arr)</strong><span>获取数组元素数量,</span><span><strong>next($arr)</strong></span><span>函数将指针移动到下一个位置,</span><span><strong>current($arr)</strong></span><span>获得当前指针下的元素。</span></span></p> <p><span>9、变长参数列表</span></p> <p><span>在定义函数时,不指定参数。在函数体内通过以下<span>3</span><span>个函数获得参数信息:</span></span></p> <p><span><strong>func_num_args()</strong><span><strong>:</strong>返回参数数量</span></span></p> <p><span><strong>func_get_arg($i)</strong><span><strong>:</strong>返回下标为</span><span>i</span><span>的参数</span></span></p> <p><span><strong>func_get_args()</strong><span><strong>:</strong>返回参数数组</span></span></p> <p><span> </span></p> <pre class="brush:php;toolbar:false">function sum(){ $num=func_num_args(); $sum=0; for($i=0;$i"; } 或者: function sum(){ $num=func_num_args(); $sum=0; $arg_list=func_get_args(); for($i=0;$i"; }<span> </span>

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

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



PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

To work on file upload we are going to use the form helper. Here, is an example for file upload.

Validator can be created by adding the following two lines in the controller.

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

CakePHP is an open source MVC framework. It makes developing, deploying and maintaining applications much easier. CakePHP has a number of libraries to reduce the overload of most common tasks.

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an
