Home >Backend Development >PHP Tutorial >Php interview questions_PHP tutorial

Php interview questions_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-14 10:12:031275browse

1. Calculate relative path


 function getpathinfo( $a, $b ) { 
    $a2array    = explode('/', $a); 
    $b2array    = explode('/', $b); 
    $pathinfo   = ''; 
    for( $i = 1; $i <= count($b2array)-2; $i++ ) { 
        $pathinfo.=$a2array[$i] == $b2array[$i] ? &#39;../&#39; : $b2array[$i].&#39;/&#39;; 
    } 
    print_R($pathinfo); 
} 
//计算出 c.php相对于e.php的相对路径应该是../../12/34  
$a          = &#39;/a/b/c/d/e.php&#39;; 
$b          = &#39;/a/b/12/34/c.php&#39;; 
getpathinfo($a, $b); 
?> 

function getpathinfo( $a, $b ) {
    $a2array    = explode(&#39;/&#39;, $a);
    $b2array    = explode(&#39;/&#39;, $b);
    $pathinfo   = &#39;&#39;;
    for( $i = 1; $i <= count($b2array)-2; $i++ ) {
        $pathinfo.=$a2array[$i] == $b2array[$i] ? &#39;../&#39; : $b2array[$i].&#39;/&#39;;
    }
    print_R($pathinfo);
}
//计算出 c.php相对于e.php的相对路径应该是../../12/34
$a          = &#39;/a/b/c/d/e.php&#39;;
$b          = &#39;/a/b/12/34/c.php&#39;;
getpathinfo($a, $b);
?>

2. Paging principle

 SELECT * FROM table &hellip;&hellip; limit   开始位置 , 操作条数  分页原理 
分页公式: 
(当前页数 - 1 )X 每页条数 , 每页条数 
Select * from table limit ($Page- 1) * $PageSize, $PageSize 

SELECT * FROM table &hellip;&hellip; limit   开始位置 , 操作条数  分页原理
分页公式:
(当前页数 - 1 )X 每页条数 , 每页条数
Select * from table limit ($Page- 1) * $PageSize, $PageSize


3. Determine whether it is post or get

 $_SERVER[&#39;REQUEST_METHOD&#39;] == &#39;POST&#39; 

$_SERVER[&#39;REQUEST_METHOD&#39;] == &#39;POST&#39;

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/477241.htmlTechArticle1. Calculate relative path function getpathinfo( $a, $b ) { $a2array = explode(/, $a ); $b2array = explode(/, $b); $pathinfo = ; for( $i = 1; $i = count($b2array)-2; $i++ ) { $pathinfo....
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