Home > Backend Development > PHP Tutorial > PHP programmer interview sharing_PHP tutorial

PHP programmer interview sharing_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-13 10:28:18
Original
852 people have browsed it

Interview summary

Today I went to a famous IT company in Beijing for an interview as a PHP programmer. Is this the first time in your life? Why aren't you nervous? Am I sick? No, this is called confidence.

First, do some written test questions.
1.What data structure is used by mysql database index? What are the benefits of doing this?
You can refer to this blog post: http://blog.csdn.net/ant_ren/article/details/2932068


2. There are two strings a and b. Determine whether string b appears in a. Case is not considered. .

My answer is: use the stripos() function to solve it.

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

Expansion:
But if the order is not considered, ask whether all the characters in the string b appear in a. . .
Then we need to use loops to solve it. Solutions are provided below:
$b_arr = str_split($b);
for(var $i=0,$len = count($b_arr); $i < $len ;  ++$i){
	if(stripos($a,$b_arr[$i])==-1)
		return false;
	return true;
}
Copy after login

3. What open source frameworks do you know?
I wrote some based on my own experience:
Laravel, PHP, jQuery. . .


4. Briefly explain session and cookie. If cookies are turned off, is the session available?
What I wrote is relatively simple:
The session is stored on the server side, and the cookie is stored on the client side. There is no direct connection between the two.
For accessing other pages. PHP_SESSIONID is placed on the browser side as a temporary cookie.
Every time the browser makes a request, it will bring the sessionid in the http header to identify itself.
If cookies are disabled, they will be automatically placed behind the URL for delivery.


5. Database optimization plan
Find this yourself on the Internet.


6. Design a Timer class to calculate the running time of the program and simply call it.
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

The following is a simple version.

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. Things you should pay attention to when building a composite index.
(1) For a table, if there is a composite index on (col1, col2), there is no need to create a single index on col1 at the same time.
(2) If the query conditions require it, you can add a composite index on (col1, col2) when there is already a single index on col1, which will improve the efficiency to a certain extent.
(3) There are not many benefits in establishing a composite index with multiple fields (including 5 or 6 fields) at the same time. Relatively speaking, establishing an index with multiple narrow fields (containing only one, or at most 2 fields) can achieve greater results. Great efficiency and flexibility.


8. Design a database table. This data table is used to store frequently inserted and queried URL data.
And explain why it is designed this way.
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


That's how I set it up.
For frequent insertions and deletions, I think the database storage engine should use MyISAM.
It would be better if we create an index on the url and name fields.

It’s not that I want to write simply. There are so many questions on just one A4 paper.

Doesn’t this force me to write simpler? But I still made some stupid mistakes. I'm trying to correct it.

A little benefit to share with everyone.

Best Wishes.



www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/802113.htmlTechArticleInterview Summary Today I went to a famous IT company in Beijing for an interview with a PHP programmer. Is this the first time in your life? Why aren't you nervous? Am I sick? No, this is called self-confidence. First, do something...
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