在我知道的程序语言中关于function这个命令都是用来定义函数的,下面我们来介绍一下关于在php中的function的用法。
用户自定义函数也称自定义函数,它们不是PHP提供的,是由程序员创建的。由于自己创建了这样的函数,所以就可以完全控制这些函数。因此可以让一个函数完全按照自己希望的方式运行。
1,申明函数
在PHP中,定义函数的方法同其他编程语言几乎一样。下面是PHP申明函数的语法结构:
实例代码如下:
- Function function_name($argument1,$argument2,$argument3,。。。。。。$argumentn)
- {
- //函数代码code
- Return 返回值;
- }
以上语法结构中,关键字的含义如下。
(1)function:用于申明用户自定义函数的关键字。
(2)function_name:要创建的函数名称。该名称将在以后被调用时使用。函数名应该唯一,因为PHP不支持重载。在命名函数的时候,需要遵循和变量命名
相同的原则。但是函数名不能以$开头,而变量可以。
(3)argument:要传递给函数的值。函数可以有多个参数,它们之间用逗号。但是参数项是可选的,可以在调用函数的时候不传递任何参数。
(4)code:是在函数被调用的时候执行的一段代码。如果有两条或者多条语句,则代码必须用大括号"{}"括起来。但是,如果只有一条代码,则不需要大括号。
(5)Return:将调用的代码需要的值返回。任何类型都可以返回,包括列表和对象。这导致函数立即结束它的运行,并且将控制权传递回它被调用的行。
2,无参数函数
代码func_1。php
实例代码如下:
- <?php
- require 'a。php';
- echo "我不会被执行!";
- ?>
3,有参数函数
PHP支持按值传递参数(默认),通过引用传递和默认参数值。可变长度参数列表仅在PHP4和后继版本中被支持。
(1)值传递参数。按值进行参数传递是PHP的默认传递方式。使用这个方法,必须在主程序调用时传递一个值(参数)。
代码sum。php
实例代码如下:
- <?php
- function sum ($a,$b)
- {
- Echo $a+$b;
- }
- sum(100,20); //开始调用该函数
- ?>
(2)引用参数。在按照值传递的时候,只有参数的副本传递给被调用的函数。但是在被调用函数内部对这些值的任何修改,都不会影响调用函数
中的原始值。引用传递其实也就是地址传递,将一个变量的地址作为参数传递。
代码valuechange。php
实例代码如下:
- <?php
- $myNum=100;
- function Valuechange ($number)
- {
- $number=$number+1;
- Echo $number 。 "<br>";
- }
- Valuechange($myNum);
- Echo $myNum;
- ?>
(3)默认值参数。使用默认的参数值传递方法,函数必须在调用的时候有一个参数。如果没有使用的值,就把默认值传递给函数参数。默认值必须是常量表达式,不是变量,
类成员或者函数调用。
提示:当使用默认参数时,任何默认参数必须放在非默认参数的右侧;否则,可能函数不会按照预期的情况工作。
代码func_default。php
实例代码如下:
- <?php
- $myNum=100;
- function Valuechange ($number)
- {
- $number=$number+1;
- Echo $number 。 "<br>";
- }
- Valuechange($myNum);
- Echo $myNum;
- ?>
波比源码 » php中function 的用法
buy levaquin 250mg generic levaquin online order
purchase avodart for sale cost flomax 0.2mg order ondansetron 8mg online
cost aldactone buy valtrex 1000mg online cheap diflucan uk
ampicillin 250mg generic order cephalexin 125mg pills erythromycin brand
fildena 50mg over the counter order generic fildena order robaxin generic
suhagra pill order estrace 1mg pills buy estrace 2mg
lamotrigine 200mg over the counter buy lamotrigine 50mg sale buy tretinoin cream
tadalis 20mg pills order voltaren 50mg pill cost diclofenac
order generic accutane order generic zithromax 250mg buy zithromax 500mg online
indomethacin pills purchase lamisil online trimox 250mg cheap
order arimidex 1mg pill order generic arimidex 1 mg cost of viagra 100mg
order deltasone 40mg without prescription cheap cialis buy viagra 100mg online cheap
buy generic accutane 10mg stromectol 12mg tablet stromectol ebay
buy doxycycline 100mg order lasix 40mg online cheap order lasix 100mg generic
prograf 5mg tablet requip 1mg brand order urso 300mg for sale
molnupiravir 200mg over the counter order omnicef 300mg without prescription lansoprazole over the counter
buy sertraline Viagra 100 mg sildenafil 50mg us
cheap cialis without prescription buy viagra next day delivery buy sildenafil 50mg sale
avlosulfon 100 mg generic buy dapsone 100mg online cheap aceon 8mg cost
order provera order microzide without prescription periactin 4mg over the counter
fluvoxamine canada buy glipizide 5mg sale buy glipizide sale
purchase nootropil pill piracetam 800mg drug cheap sildenafil online
zithromax 250mg for sale buy azithromycin 250mg sale neurontin 100mg usa
cialis 5mg canada tadalafil 20mg uk order anafranil 25mg without prescription
chloroquine for sale cenforce tablet buy olumiant 2mg pills
purchase zyprexa without prescription brand diovan valsartan pills
order amlodipine pill buy generic amlodipine 10mg tadalafil 5mg oral
brand omeprazole 20mg blackjack poker online free roulette
lopressor order vardenafil 10mg without prescription buy levitra online cheap
purchase clomiphene generic buy albuterol generic play poker online free
dapoxetine 60mg ca dapoxetine 60mg without prescription levothyroxine over the counter
order orlistat 120mg generic generic zovirax 400mg buy acyclovir 800mg online cheap
cialis 40mg propranolol uk order clopidogrel 75mg for sale
cialis pills 20mg buy inderal 10mg generic buy plavix 75mg for sale
buy zyloprim for sale purchase rosuvastatin for sale zetia brand
order generic methotrexate 10mg methotrexate online order buy reglan 20mg generic
cozaar 25mg drug buy losartan 50mg online cheap topamax ca
buy ozobax online cheap ozobax order buy generic toradol
zantac 300mg usa generic meloxicam 15mg order celecoxib 100mg pills
brand tamsulosin 0.4mg buy generic zofran 4mg aldactone ca
cialis daily cost ampicillin 500mg sale order cipro 1000mg pills
cheap cephalexin 500mg clindamycin over the counter buy erythromycin 500mg online
sildenafil drug cialis 40mg over the counter buy cialis 40mg
online blackjack free casino slot tadalafil 40mg for sale
purchase sildalis sale brand estrace 2mg order lamictal generic
prednisone pill cost amoxicillin 500mg buy amoxil 250mg pills
order viagra 100mg online cheap viagra 50mg brand tadalafil 40mg usa
online casino with free signup bonus real money usa best ed pills at gnc tadalafil medication
fildena 100mg us fildena 50mg pills buy generic budesonide
order retin gel for sale order retin gel generic order avana 200mg online
tadalafil 20mg uk indomethacin price indomethacin 75mg tablet
buy lamisil pills order terbinafine without prescription buy generic amoxicillin 500mg
naprosyn drug lansoprazole pills order lansoprazole 30mg
proventil 100 mcg us protonix sale buy cipro online
purchase singulair online cheap buy sildenafil 50mg buy sildenafil 100mg pill
buy cialis 10mg pills Buy cialis in usa order cialis 5mg generic
ivermectin 200 mcg stromectol 12mg ca cheap dapsone
write me a paper arava 20mg for sale order sulfasalazine pills
buy diamox 250mg sale buy acetazolamide online cheap imuran ca
purchase lanoxin pills order digoxin pill molnunat 200 mg cheap
dapoxetine 30mg tablet avana 100mg tablet domperidone 10mg tablet
fosamax price buy alendronate 70mg online cheap motrin 600mg uk
nortriptyline 25 mg cheap nortriptyline 25 mg cheap buy paroxetine 10mg pills
pepcid for sale buy famotidine 20mg online brand remeron 30mg
buy generic tricor 160mg purchase tricor pill sildenafil us
nexium online lasix 100mg price lasix cost
tadalafil 5mg us Generic cialis next day shipping hims ed pills
modafinil 100mg without prescription buy provigil generic phenergan pills
serophene order online buy atorvastatin 80mg sale prednisolone 10mg over the counter
buy ondansetron 8mg cheap amoxil without prescription purchase bactrim without prescription
purchase isotretinoin online order amoxicillin 500mg without prescription cost zithromax 250mg
ventolin inhalator over the counter order amoxiclav sale buy augmentin 375mg generic
azathioprine brand naprosyn 250mg uk naprosyn without prescription
dapsone 100 mg canada tenormin price buy tenormin 100mg online
warfarin for sale purchase warfarin without prescription zyloprim 300mg oral
buy lipitor paypal cheap sildenafil online viagra online
femara 2.5 mg tablet viagra pills 25mg viagra overnight shipping
cialis 5mg pill cialis prices ed pills that really work
order amoxicillin 1000mg sale buy prednisolone 10mg generic order prednisolone 5mg pill
buy isotretinoin 20mg pill buy amoxicillin azithromycin 500mg drug
buy cheap gabapentin lasix 40mg tablet purchase doxycycline without prescription
order albuterol without prescription augmentin canada buy synthroid paypal
clomid 50mg us plaquenil drug plaquenil 400mg uk
buy synthroid 100mcg for sale clomid 50mg ca where to buy levitra without a prescription
albendazole 400mg brand buy abilify 30mg generic provera 5mg tablet
order praziquantel 600mg cheap microzide 25 mg cost cyproheptadine
order methotrexate 2.5mg online order methotrexate 10mg without prescription reglan online order
cozaar cheap order esomeprazole 20mg order topiramate 100mg for sale
rosuvastatin where to buy buy ezetimibe 10mg generic buy motilium 10mg pills
order toradol 10mg generic purchase toradol online cheap buy cheap propranolol
zantac cheap order ranitidine 300mg online buy generic celebrex
plavix price order plavix pill nizoral 200 mg us
buy tamsulosin generic order spironolactone 25mg generic aldactone without prescription
order cymbalta 40mg for sale cymbalta 20mg pill order nootropil generic
purchase betnovate generic clomipramine pills sporanox 100 mg us
buy ipratropium 100 mcg generic purchase combivent pill cheap zyvox 600 mg
buy nebivolol generic valsartan buy online order clozaril
buy starlix pill order nateglinide generic how to get atacand without a prescription
purchase simvastatin generic cheap generic viagra order sildenafil 50mg online cheap
carbamazepine 200mg ca tegretol online buy order lincocin 500 mg pills
buy tadalafil 10mg for sale oral tadalafil 10mg order sildenafil 50mg online
estrace 2mg brand prazosin 2mg oral prazosin 2mg uk
fluconazole price buy ampicillin generic cipro 1000mg brand
mebendazole usa order tretinoin cream for sale tadalis 10mg ca
order cleocin 150mg sale buy erythromycin 250mg pill buy fildena online cheap
order indomethacin 75mg for sale purchase indomethacin generic buy suprax 100mg generic
tamoxifen 20mg generic ceftin 250mg canada how to get cefuroxime without a prescription
careprost brand purchase trazodone without prescription desyrel cost
buy clonidine 0.1 mg pill tiotropium bromide sale buy spiriva 9 mcg pill
minomycin online actos 30mg cost cost pioglitazone
leflunomide 20mg ca sildenafil 25mg buy sulfasalazine pills
isotretinoin 20mg for sale azithromycin sale zithromax online order
azipro without prescription cheap azipro 500mg purchase neurontin
buy furosemide paypal ventolin pill order albuterol 4mg online
purchase vardenafil generic buy tizanidine generic buy hydroxychloroquine online cheap
olmesartan price order depakote 500mg generic order divalproex 250mg sale