Podobne
- Strona startowa
- [eBooks.PL]Praca Magisterska Projekt serwisu informacyjnego WWW
- adobe.photoshop.7.pl.podrÄcznik.uzytkownika.[osloskop.net]
- Linux. .Mandrake.10.Podręcznik.Użytkownika.[eBook.PL] (3)
- Adobe.Photoshop.7.PL.podręcznik.uzytkownika.[osloskop.net]
- Chmielewska Joanna Lesio (www.ksiazki4u.prv.pl)
- Heath Lorraine Najwspanialsi kochankowie Londynu 01 Odzyskana miłoÂść
- Kuttner Henry Kraina Mroku
- Cudzoziemiec Zygmunt Zeydler Zborowski
- Brayfield Celia Książę
- Wstęp do filozofii Antoni B. Stępień
- zanotowane.pl
- doc.pisz.pl
- pdf.pisz.pl
- nea111.xlx.pl
Cytat
Do celu tam się wysiada. Lec Stanisław Jerzy (pierw. de Tusch-Letz, 1909-1966)
A bogowie grają w kości i nie pytają wcale czy chcesz przyłączyć się do gry (. . . ) Bogowie kpią sobie z twojego poukładanego życia (. . . ) nie przejmują się zbytnio ani naszymi planami na przyszłość ani oczekiwaniami. Gdzieś we wszechświecie rzucają kości i przypadkiem wypada twoja kolej. I odtąd zwyciężyć lub przegrać - to tylko kwestia szczęścia. Borys Pasternak
Idąc po kurzych jajach nie podskakuj. Przysłowie szkockie
I Herkules nie poradzi przeciwko wielu.
Dialog półinteligentów równa się monologowi ćwierćinteligenta. Stanisław Jerzy Lec (pierw. de Tusch - Letz, 1909-1966)
[ Pobierz całość w formacie PDF ]
.Notatka: This function was added to the CVS code after release of PHP 4.4pl1call_user_func (PHP 3>= 3.3, PHP 4 )Call a user function given by the first parametermixed call_user_func ( string function_name [, mixed parameter [, mixed.]]) \linebreakCall a user defined function given by thefunction_nameparameter.Take the following:function barber ($type) {print "You wanted a $type haircut, no problem";}call_user_func ( barber , "mushroom");call_user_func ( barber , "shave");603FunctionsSee also: call_user_func_array(), call_user_method(), call_user_method_array().create_function (PHP 4 >= 4.1)Create an anonymous (lambda-style) functionstring create_function ( string args, string code) \linebreakCreates an anonymous function from the parameters passed, and returns a unique name for it.Usually theargswill be passed as a single quote delimited string, and this is also recommended forthecode.The reason for using single quoted strings, is to protect the variable names from parsing,otherwise, if you use double quotes there will be a need to escape the variable names, e.g.\$avar.You can use this function, to (for example) create a function from information gathered at run time:Przykład 1.Creating an anonymous function with create_function()$newfunc = create_function( $a,$b , return "ln($a) + ln($b) = ".log($a * $b); );echo "New anonymous function: $newfunc\n";echo $newfunc(2,M_E)."\n";// outputs// New anonymous function: lambda_1// ln(2) + ln(2.718281828459) = 1.6931471805599Or, perhaps to have general handler function that can apply a set of operations to a list of parameters:Przykład 2.Making a general processing function with create_function()function process($var1, $var2, $farr) {for ($f=0; $f =0) {return "b*a^2 = ".$b*sqrt($a);} else {return false;} ;$f2 = "return \"min(b^2+a, a^2,b) = \".min(\$a*\$a+\$b,\$b*\$b+\$a);";$f3 = if ($a > 0 && $b != 0) {return "ln(a)/b = ".log($a)/$b; } else { re-turn false; } ;$farr = array(create_function( $x,$y , return "some trig: ".(sin($x) + $x*cos($y)); ),create_function( $x,$y , return "a hypotenuse: ".sqrt($x*$x + $y*$y); ),create_function( $a,$b , $f1),create_function( $a,$b , $f2),create_function( $a,$b , $f3));echo "\nUsing the first array of anonymous functions\n";echo "parameters: 2.3445, M_PI\n";process(2.3445, M_PI, $farr);604Functions// now make a bunch of string processing functions$garr = array(create_function( $b,$a , if (strncmp($a,$b,3) == 0) return "** \"$a\" . and \"$b\"\n** Look the same to me! (looking at the first 3 chars)"; ),create_function( $a,$b , ; return "CRCs: ".crc32($a)." , ".crc32(b); ),create_function( $a,$b , ; return "similar(a,b) = ".similar_text($a,$b,&$p)."($p%)";);echo "\nUsing the second array of anonymous functions\n";process("Twas brilling and the slithy toves", "Twas the night", $garr);and when you run the code above, the output will be:Using the first array of anonymous functionsparameters: 2.3445, M_PIsome trig: -1.6291725057799a hypotenuse: 3.9199852871011b*a^2 = 4.8103313314525min(b^2+a, a^2,b) = 8.6382729035898ln(a/b) = 0.27122299212594Using the second array of anonymous functions** "Twas the night" and "Twas brilling and the slithy toves"** Look the same to me! (looking at the first 3 chars)CRCs: -725381282 , 1908338681similar(a,b) = 11(45.833333333333%)But perhaps the most common use for of lambda-style (anonymous) functions is to create callbackfunctions, for example when using array_walk() or usort()Przykład 3.Using anonymous functions as callback functions$av = array("the ","a ","that ","this ");array_walk($av, create_function( &$v,$k , $v = $v."mango"; ));print_r($av); // for PHP 3 use var_dump()// outputs:// Array// (// [0] => the mango// [1] => a mango// [2] => that mango// [3] => this mango// )// an array of strings ordered from shorter to longer$sv = array("small","larger","a big string","it is a string thing");print_r($sv);// outputs:// Array// (605Functions// [0] => small// [1] => larger// [2] => a big string// [3] => it is a string thing// )// sort it from longer to shorterusort($sv, create_function( $a,$b , return strlen($b) - strlen($a); ));print_r($sv);// outputs:// Array// (// [0] => it is a string thing// [1] => a big string// [2] => larger// [3] => small// )func_get_arg (PHP 4 )Return an item from the argument listmixed func_get_arg ( int arg_num) \linebreakReturns the argument which is at thearg_num th offset into a user-defined function s argument list.Function arguments are counted starting from zero.func_get_arg() will generate a warning if calledfrom outside of a function definition.Ifarg_numis greater than the number of arguments actually passed, a warning will be generatedand func_get_arg() will returnFALSE.= 2) {echo "Second argument is: ".func_get_arg (1)."\n";}}foo (1, 2, 3);?>func_get_arg() may be used in conjunction with func_num_args() and func_get_args() to allowuser-defined functions to accept variable-length argument lists.606FunctionsNotatka: This function was added in PHP 4.func_get_args (PHP 4 )Returns an array comprising a function s argument listarray func_get_args ( void) \linebreakReturns an array in which each element is the corresponding member of the current user-definedfunction s argument list.func_get_args() will generate a warning if called from outside of afunction definition.= 2) {echo "Second argument is: ".func_get_arg (1)."\n";}$arg_list = func_get_args();for ($i = 0; $ifunc_get_args() may be used in conjunction with func_num_args() and func_get_arg() to allowuser-defined functions to accept variable-length argument lists.Notatka: This function was added in PHP 4.func_num_args (PHP 4 )Returns the number of arguments passed to the functionint func_num_args ( void) \linebreakReturns the number of arguments passed into the current user-defined function.func_num_args()will generate a warning if called from outside of a user-defined function.607Functionsfunc_num_args() may be used in conjunction with func_get_arg() and func_get_args() to allowuser-defined functions to accept variable-length argument lists.function_exists (PHP 3>= 3.7, PHP 4 )ReturnTRUEif the given function has been definedbool function_exists ( string function_name) \linebreakChecks the list of defined functions, both built-in (internal) and user-defined, forfunction_name.ZwracaTRUEw przypadku sukcesu,FALSEw przypadku porażki.if (function_exists( imap_open )) {echo "IMAP functions are available.\n";} else {echo "IMAP functions are not available.\n";}Note that a function name may exist even if the function itself is unusable due to configuration orcompiling options (with the image functions being an example).Also note that function_exists()will returnFALSEfor constructs, such as include_once() and echo().See also method_exists() and get_defined_functions().get_defined_functions (PHP 4 >= 4.4)Returns an array of all defined functionsarray get_defined_functions ( void) \linebreakThis function returns an multidimensional array containing a list of all defined functions, bothbuilt-in (internal) and user-defined.The internal functions will be accessible via$arr["internal"], and the user defined ones using$arr["user"](see example below).function myrow($id, $data) {608Functionsreturn "$id$data\n";}$arr = get_defined_functions();print_r($arr);Will output something along the lines of:Array([internal] => Array([0] => zend_version[1] => func_num_args[2] => func_get_arg[3] => func_get_args[4] => strlen[5] => strcmp[6] => strncmp.[750] => bcscale[751] => bccomp)[user] => Array([0] => myrow))See also get_defined_vars() and get_defined_constants().register_shutdown_function (PHP 3>= 3
[ Pobierz całość w formacie PDF ]