PHP Programmer interview Sharing

Source: Internet
Author: User
Tags end explode key return string mysql database
Interview Summary

Today, I went to a famous Beijing IT company for a PHP programmer interview. This is the first time in life, why not nervous? I'm not sick. No, it's called confidence, huh?

The first is to do some writing questions.
The data structure used by the 1.mysql database index? What's the benefit of doing that?
Refer to this blog post: http://blog.csdn.net/ant_ren/article/details/2932068


2. There are two strings A and B to determine whether the B string appears in a. Do not consider the case.

My answer is: Use the Stripos () function to solve.

if (Stripos ($a, $b) >-1)
	echo "B in a";
else
	echo "b not in a";

Expand:
But if you don't consider the order, ask if the characters in the B string all appear in a ...
Then we need to use a loop to solve it. The solution is 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;
}

3. You know the open source framework?
I have written some of my own experiences:
Laravel,php,jquery ...


4. Briefly explain session and cookies. Is closing cookie,session available?
My writing is relatively simple:
The session is stored on the server side and the cookie is stored on the client. There is no direct link between the two.
For access to other pages. Php_sessionid is placed as a temporary cookie on the browser side.
Each time a browser makes a request, it is SessionID in the HTTP header to identify itself.
If cookies are disabled, they are automatically passed behind the URL.


5. Database Optimization Scheme
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;//program run start time 
	private $StopTime = 0;//program run end time 
	private $TimeSpent = 0;//program Shipping The line takes time 


	function start () {//program run start 
		$this->starttime = Microtime (); 
	} 
	function Stop () {//program run end 
		$this->stoptime = Microtime (); 
	} 
	function spent () {//The time it takes to run 
		if ($this->timespent) {return 
			$this 
		} 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). " Seconds ";//Return to get program run time Difference 
		} 
	} 
$timer = new timer (); 
$timer->start (); 
//... The code that the program runs 
$timer->stop (); 

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 ();


7. To establish a composite index should pay attention to matters.
(1) For a table, it is not necessary to establish a single index on col1 if there is a composite index on (col1,col2).
(2) If the query conditions require, you can add a composite index on (col1,col2) in the case of an existing single index on col1, and there is a certain increase in efficiency.
(3) A composite index with multiple fields (5, 6 fields) at the same time does not have a lot of benefits, whereas indexes that create multiple narrow fields (one or at most 2 fields) can achieve greater efficiency and flexibility.


8. Design a database table. The data table is used to store URL data that is frequently inserted and queried.
And explain why this is so designed.
Create table URL (
	' id ' int (one) NOT null primary key auto_increment comment ' primary key ',
	' url ' varchar (255) NOT NULL comme NT "URL content",
	' name ' varchar () comment "url name"
) Engine=myisam


That's how I built it.
Often insert and delete, I feel that the database storage engine should use MyISAM.
It would be nice if you set up an index on the Url,name field again.

Not that I want to write a simple. So many questions on a piece of A4 paper.

Isn't that forcing me to write a simple point? But I still made some low-level mistakes. I'm trying to correct it.

A little welfare, share it to everyone.

Best Wishes.





Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.