search
Homephp教程php手册PHP函数功能讲解

PHP函数功能讲解

Jun 13, 2016 am 10:39 AM
phpfunctionuseFunctionofexplain

PHP的真正威力源自于它的函数,但有些PHP函数并没有得到充分的利用,也并不是所有人都会从头到尾一页一页地阅读手册和函数参考,这里将向您介绍这些实用的函数和功能。

  1、任意参数数目的函数
  你可能已经知道,PHP允许定义可选参数的函数。但也有完全允许任意数目的函数参数的方法。以下是可选参数的例子:

以下为引用的内容: 
//functionwith2optionalarguments  
functionfoo($arg1=”,$arg2=”){ 
echo“arg1:$arg1 ”;  
echo“arg2:$arg2 ”; 
}  

foo(‘hello’,world’);  
/*prints:  
arg1:hello  
arg2:world  
*/  

foo();  
/*prints:  
arg1:  
  20. arg2:  
*/

  现在让我们看看如何建立能够接受任何参数数目的函数。这一次需要使用func_get_args()函数:

以下为引用的内容: 
//yes,theargumentlistcanbeempty  
functionfoo(){ 
//returnsanarrayofallpassedarguments  
$args=func_get_args(); 
foreach($argsas$k=>$v){  
echo“arg”.($k 1).”:$v ”;  

}  

foo();  
/*printsnothing*/  

foo(‘hello’);  
/*prints  
arg1:hello  
*/  

foo(‘hello’,‘world’,‘again’);  
/*prints  
arg1:hello  
arg2:world  
arg3:again  
*/

Statement
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 Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

MinGW - Minimalist GNU for Windows

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.