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

Video Face Swap

Video Face Swap

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

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 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)

Hot Topics

Java Tutorial
1666
14
PHP Tutorial
1273
29
C# Tutorial
1252
24
PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP: A Key Language for Web Development PHP: A Key Language for Web Development Apr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP in Action: Real-World Examples and Applications PHP in Action: Real-World Examples and Applications Apr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP vs. Python: Understanding the Differences PHP vs. Python: Understanding the Differences Apr 11, 2025 am 12:15 AM

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

The Enduring Relevance of PHP: Is It Still Alive? The Enduring Relevance of PHP: Is It Still Alive? Apr 14, 2025 am 12:12 AM

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP and Python: Code Examples and Comparison PHP and Python: Code Examples and Comparison Apr 15, 2025 am 12:07 AM

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

PHP vs. Other Languages: A Comparison PHP vs. Other Languages: A Comparison Apr 13, 2025 am 12:19 AM

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

PHP and Python: Different Paradigms Explained PHP and Python: Different Paradigms Explained Apr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

See all articles