Home php教程 php手册 php学习笔记(一)

php学习笔记(一)

Jun 06, 2016 pm 07:42 PM
php shell study quotation marks implement Equivalent to notes operator

1.执行运算符是反引号 (``), 相当于 shell_exec() 函数,执行一个系统命令 $out=`dir`;//列出当前的目录和文件信息 2.定义常量 define(str,this is a const variableBR);echo str; 3.字符串 用单引号或双引号括起来。区别是在双引号中出现变量时会替换为变量

1.执行运算符是反引号(``),相当于shell_exec()函数,执行一个系统命令

$out=`dir`;//列出当前的目录和文件信息
Copy after login

2.定义常量

define("str","this is a const variable<br>");
echo str;
Copy after login

3.字符串

用单引号或双引号括起来。区别是在双引号中出现变量时会替换为变量的值。

$a=10;
echo("variable is $a");
echo('variable is $a');
//结果为:variable is 10variable is $a 
Copy after login


4、接受数据

使用变量$_POST读取表单数据。如果控件的name属性为c1,则用下面的方式获取他的值:

$_POST[`c1`]

Index.php文件

Copy after login

ShowInfo.php文件

if(isset($_POST['submit']) && $_POST['submit']){
echo("<br>用户名:".$_POST['username']."<br>");
   }
Copy after login

5、接受网址中的参数信息

在网址中传递参数,格式为:

http://网址/网页文件?参数1>=&参数2>=

接受参数:使用变量:$_GET['参数名']

<a href="ShowInfo.php?name=Johney&sex=man">submit</a>
ShowInfo.php文件
echo ("name: ".$_GET['name']."<br>");
echo ("sex: ".$_GET['sex']);
Copy after login

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 )
 
Copy after login

多维数组

$arr[0][0]="CPU";
$arr[2][3]="memory";
print_r($arr);
//结果:
Array ( [0] => Array ( [0] => CPU ) [2] => Array ( [3] => memory ) )
Copy after login

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 )
Copy after login

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>
Copy after login
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

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

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

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

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

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

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

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

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

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

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

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 Quick Guide CakePHP Quick Guide Sep 10, 2024 pm 05:27 PM

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.

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

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

See all articles