Home > Backend Development > PHP Tutorial > Four PHP application small functions_PHP tutorial

Four PHP application small functions_PHP tutorial

WBOY
Release: 2016-07-13 17:23:49
Original
844 people have browsed it

1. How to view variable content

There is a var_dump($var) function in php4, which is used to dump the content of a variable (various types of variables), but the output of this function is not suitable for display in html pages. . You can write a function yourself as follows:
function dump( $var ) {
echo "
";
var_dump( $var );
echo "
";
}

Very suitable for debugging!

In php3, you can only dump the contents of an array recursively, but there is nothing you can do about objects. It seems like the previous article The Dump_Array function is such a function. :)

2. Static variables

function test()
{
static $s_val;
$s_val+=2 ;
return $s_val;
}

echo test();//2
echo test();//4
?>

3. A way to avoid the same name appearing multiple times
#----------------avoid the same name-------------

for($checkname=0;$checkname{
if ($name[$checkname]==$name[$num])
{
$num--;
break;
}
}

4. Get the extension of a file
Use this small function:

function fileextname ($filename)
{
$retval="";
$pt=strrpos($filename, ".");
if ($pt) $retval=substr($filename, $ pt+1, strlen($filename) - $pt);
return ($retval);

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/532195.htmlTechArticle1. How to view variable content There is a var_dump($var) function in php4, which is used to dump the content of a variable (various types of variables), but the output of this function is not suitable for html pages...
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template