php软件工程师面试分享

WBOY
Release: 2016-06-13 11:59:34
Original
797 people have browsed it

php程序员面试分享
面试总结

今天去了北京著名IT公司进行PHP程序员的面试。这是人生第一次么,怎么不紧张?我是不是有病。不是,这叫自信呵.

首先是做一些笔试题。
1.mysql数据库索引使用的数据结构?这样做的好处是?
可以参考这篇博文:http://blog.csdn.net/ant_ren/article/details/2932068


2.有两个字符串a和b,判断b字符串是否出现在a中。不考虑大小写。。

我的答案是:使用stripos()这个函数来解决的。

if(stripos($a,$b)>-1)	echo "b in a";else	echo "b not in a";
Copy after login

拓展:
但是如果是不考虑顺序的话,问b字符串中的字符是否全部出现在a中。。。
那我们就需要用循环来解决的。下面提供解决方案:
$b_arr = str_split($b);for(var $i=0,$len = count($b_arr); $i <br>3.你知道的开源框架?<br>我按照自己的经验写了一些:<br>Laravel,PHP,jQuery。。。<br><br><br>4.简单解释session 和cookie。关闭cookie,session是否可用?<br>我写的比较简单:<br>session存储在服务器端,cookie存储在客户端。两者没有直接的联系。<br>对于访问其他的页面。PHP_SESSIONID是作为一个临时cookie放在浏览器端的。<br>每次浏览器发出的请求,都会在http header里 带上 sessionid来标识自己。<br>如果禁用cookie,那么会自动放在url后面进行传递。<br><br><br>5.数据库优化方案<br>这个自己在网络上找一下。<br><br><br>6.设计一个Timer类,用来计算程序运行的时间,并且简单的调用它。<br><pre code_snippet_id="390403" snippet_file_name="blog_20140613_3_819192" name="code" class="javascript">class Timer { 	private $StartTime = 0;//程序运行开始时间 	private $StopTime = 0;//程序运行结束时间 	private $TimeSpent = 0;//程序运行花费时间 	function start(){//程序运行开始 		$this->StartTime = microtime(); 	} 	function stop(){//程序运行结束 		$this->StopTime = microtime(); 	} 	function spent(){//程序运行花费的时间 		if ($this->TimeSpent) { 			return $this->TimeSpent; 		} else { 			list($StartMicro, $StartSecond) = explode(" ", $this->StartTime); 			list($StopMicro, $StopSecond) = explode(" ", $this->StopTime); 			$start = doubleval($StartMicro) + $StartSecond; 			$stop = doubleval($StopMicro) + $StopSecond; 			$this->TimeSpent = $stop - $start; 			return substr($this->TimeSpent,0,8)."秒";//返回获取到的程序运行时间差 		} 	} } $timer = new Timer(); $timer->start(); //...程序运行的代码 $timer->stop(); echo "程序运行时间为:".$timer->spent(); 
Copy after login


下面是简单版的。

class Timer{	private $t = 0;	public function start(){		$this->t = microtime(true);	}	public function stop(){		return microtime(true)- $this->t;	}}$time = new Timer();$time->start();//do somethings...$t = $time->stop();
Copy after login


7.建立复合索引应该注意的事项。
(1)对一张表来说,如果有一个复合索引 on   (col1,col2)就没有必要同时建立一个单索引 on col1。
(2)如果查询条件需要,可以在已有单索引 on col1的情况下,添加复合索引on   (col1,col2),对于效率有一定的提高。
(3)同时建立多字段(包含5、6个字段)的复合索引没有特别多的好处,相对而言,建立多个窄字段(仅包含一个,或顶多2个字段)的索引可以达到更好的效率和灵活性。


8.设计一张数据库表。该数据表用来存储经常插入和查询的url数据。
并解释为什么这么设计的原因。
create table url(	`id` int(11) not null primary key auto_increment comment "主键",	`url` varchar(255) not null comment "url 内容",	`name` varchar(50) comment "url对应的名称")ENGINE=MyISAM
Copy after login


我是这么建立的。
经常插入和删除,我觉的数据库存储引擎应该使用MyISAM。
如果再在url,name字段上建立一个索引就更好了。

不是我想简单写啊。这么多题目就一张A4纸啊。

这不是逼着我写简单点吗?不过我还是犯了一些低级的错误。我正在努力改正。

一点福利,分享给大家。

Best Wishes.



Related labels:
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!