php面试题

<?php
    //面试题
    /**
    *题目类型1
    *cookie的工作原理是什么,设置cookie,并获取数据;设置cookie过期时间
    */
    setcookie('mycookie','testValue',time()+60); //设置了cookie,并过期时间为一分钟
    echo $_COOKIE['mycookie'];
    echo $HTTP_COOKIE_VARS['mycookie'];
    print_r($_COOKIE);//打开印cookie数据
    /**
    *题目类型2
    *遍历一个文件夹下的所有文件和子文件夹,查找扩展名为.zip的所有文件
    *@param string $dir
    *@return array
    */
    echo "<pre>";
    function myScandir($dir){
        $files=array();
        $dir_list=scandir($dir);//列出指定路径中的文件和目录

        foreach($dir_list as $file){
            if($file=='.' || $file=='..')
                continue;
            if(is_dir($dir.'/'.$file)){
                $files[$file]=myScandir($dir.'/'.$file);
            }else{
                if(substr(strtolower($file),-4)=='.zip'){
                    $files[]=$file;
                }
            }
        }
        return $files;
    }
    $files=myScandir('./');
    print_r($files);
    
    /**
    *题目类型3
    *把数组中的值进行排序
    *@return array
    */
    
    /**
    *题目类型4
    *try与catch的使用
    *@return array
    */
         try {  
            $mgr = new CommandManager();  
            $cmd = $mgr->getCommandObject("realcommand");  
            $cmd->execute();  
        } catch (Exception $e) {  
            print $e->getMessage();  
            exit();  
        }
    /**题目类型5
     *写一个php函数,尽可能高效的,从一个url中提取出文件的扩展名。
     *$url=http://eladies.sina.com.cn/qg/2013/0811/06461231319.shtml   
    */

    function get_extend($url){
        return end(explode('.',$url));
    }
    /**
    *php 斐波那契数列:1 1 2 3 5 8 13 21 34 .....,求出第30位数字是多少,用递归算法
    */
    function deGui($n){
       
        if($n==0 || $n==1 || $n==2){
            return 1;
        }else{
            $res=deGui($n-1)+deGui($n-2);
            return $res;
        }
    }
    deGui(30);
/**
*public private protected 类型的区别,输入打印结果
*/
class a{
        protected $c;
        public function __construct(){
            $this->c=10;
        }
    }
    class b extends a {
        function print_data(){
            return $this->c;
        }
    }
   $abc=new b();
   结果:10;

/**
*php引用传递,请问下输出的结果是?
*/
function printString(&$string){
      $string="456!";
      return $string;
}
$string="123";
printString($string);
echo $string;
结果:456!(如果非引用传递,结果为123);
/**
*Mysql面试题
*常见SQL面试题——第31到40条记录,键为ID整型,递增(可能不连续)
*/

-->select  * from a where id not in (select id from a order by id limit 30) order by id limit 10

   查询前十条记录,但条件是:ID不在前三十条的ID里面(升序)

-->select  * from (select  id from aorder by id desc(降序) limit 40) order by id limit 10

  查询前十条记录,但条件是:ID取出的是以ID按降序排列的前四十条记录里面的。


请说明php中传值与传引用的区别。什么时候传值什么时候传引用?


按值传递:函数范围内对值的任何改变在函数外部都会被忽略
按引用传递:函数范围内对值的任何改变在函数外部也能反映出这些修改
优缺点:按值传递时,php必须复制值。特别是对于大型的字符串和对象来说,这将会是一个代价很大的操作
按引用传递则不需要复制值,对于性能提高很有好处。


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值