php 函数如 function tes($a,$b,$c='3',$d='4') echo $a.$b.$c.$d; 现在我想改变$d值,$c的值默认,怎么调用啊
参考知识1
你想要的这个功能是PHP不具备的。如果你要给$d赋值,那个$c也得必须赋值。不过可以变相的解决这个问题。举个例子。比如$c有个规矩就是它一定不是非空的。那么给它传值为空时则使用默认值。那么在调用函数时 tes(1,2,'',4);函数内部去处理这种情况。另外还有别的方法,例如把函数参数改为一数组或者一个字串(可以用parse_str解析一个串到变量),另外也有方法就是巧用func_开头的几个函数。 参考资料:http://www.cnno3.com/forum-80-1.html 我的意思是,在调用是,$c的值是默认值,$d的值我想重新赋值。怎么调用啊,大侠 函数调用时参数的匹配问题。默认值如果不是在最后一个参数,则有默认值的参数之后的参数必须都有默认值。
给一个具体的代码吧:
test("a=6&b=2&d=11");
function test($str)
$a=$b='';
$c=3;$d=4;
parse_str($str);
echo $a.$b.$c.$d;
function tes($a,$b,$c='3',$d='4')
if(empty($c)) $c = '3';
if(empty($d)) $d = '4';
echo $a.$b.$c.$d;
test (1,2,3,4);
test (1,2,NULL,4)
得到的结果是一样的
参考知识C
three yrs . old woman wearing a gown to sing carols sought following kicking high heel pumps do not arm
High-heeled shoes
If you search for a 93-year-old, how are you currently likely to invest your day? To find out the old lady: Jingshan Park these days to sing, dance tomorrow, Beihai Park, a special afternoon went to her home to interview concerning the old lady a stare: "afternoon fail, should i play cards."
Yesterday, all year round in Jingshan Park to sing the very first 15 folk join a chorus, spontaneously organized "Ode dedicated to the party,christian louboutin outlet," the variety show. 93-year-old Sun Fengying old lady on stage has become probably the most "shocking" in a scene - ushered inside a dozen civil photographer Changqiangduanbao whilst frantically. Jingshan Park staff told reporters the woman frequently to participate in activities, "normal wear dress",christian louboutin pumps, although avoid seeing the gown yesterday, plus body, 1 couple of feet can twenty-three cm high black heels, indeed, so the reporter was surprised. A "country" over and over, waves of applause from your audience.
Where the old "new song we sing" Choir members have minimum 60 years of age, in addition to Sun Fengying older people, the c's there is a 85-year-old Father, your body wonderfully. 93 many years of his polished, to ensure that the peak of the old lady Sun "shrink" to at least one.4 meters, can provide the task of pennants was handed to her. A Changba, that old lady located on high heel pumps walking down in the stage,discount christian louboutin hot sale, don't mix don't assist, walking light. They asked the regiment who lived far, everybody unanimously indicate that old lady Sun. Daxing elderly live each and every day four:00 stand up, 5:00 in to the city to exercise the very first bus ride, generally in Jingshan activities have drawn 1 day to the North Sea dance. She pointed to the foot from the shoe, said: "must dance with high heels." No surprise old people are extremely particular about the dress, that old lady is Nanjing Sun, tailor origin, great to accomplish cheongsam, the 1950s Beijing, "the most to determine Beijingers aren't utilized to use clothes you do not leng straight board, no lines, the garments do using the barrel-like,christian louboutin sale, for the body of your get away. "to Beijing following the existing man brought out a number of disciples, after which a respectable retirement, now is the day play,Discount Christian Louboutin Slingbacks, "you have to seize the time to try out, until a 'kick', it do not regret it." Before leaving, she asked the correspondent case
参考知识D
tes(1,2,5,4);就像$a,$b一样追问
在调用函数时是可以省略含有默认值的参数,但是在此之后的参数也将使用默认值