Php programmer interview sharing

Source: Internet
Author: User

Interview Summary

Today, I went to a famous IT company in Beijing to interview PHP programmers. Is this the first time in my life? Why not be nervous? Are I ill. No, this is self-confidence.

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


2. There are two strings a and B to determine whether string B appears in string. Case-insensitive ..

My answer is: Use the stripos () function.

 

if(stripos($a,$b)>-1)echo "b in a";elseecho "b not in a";

 

Expansion:
However, if the sequence is not considered, ask if all the characters in string B appear in string...
Then we need to use loops to solve the problem. The solution is as follows:
$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. Do you know the open-source framework?
Based on my own experience, I wrote some:
Laravel, PHP, jQuery...


4. Simple Explanation of session and cookie. Disable cookie. Is the session available?
I wrote the following simple:
Session is stored on the server, and cookie is stored on the client. There is no direct connection between the two.
For accessing other pages. PHP_SESSIONID is used as a temporary cookie on the browser end.
Each request sent by the browser carries a sessionid in the http header to identify itself.
If the cookie is disabled, it is automatically placed behind the url for transmission.


5. Database optimization solution
Find this on the network.


6. Design a Timer class to calculate the running time and call it easily.
Class Timer {private $ StartTime = 0; // start time of the program running private $ StopTime = 0; // end time of the program running private $ TimeSpent = 0; // duration of the program running function start () {// program running start $ this-> StartTime = microtime ();} function stop () {// program running end $ this-> StopTime = microtime ();} function spent () {// time spent on running the program 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 ). "seconds"; // return the time difference between the obtained program running. }}$ timer = new Timer (); $ timer-> start ();//... code for running the program $ timer-> stop (); echo "running time :". $ timer-> spent ();

 

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. Precautions for 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 condition is required, you can add a composite index on (col1, col2) with a single index on col1, which improves the efficiency.
(3) Creating a composite index with multiple fields (including five or six fields) at the same time has no special benefit. Relatively speaking, creating multiple narrow fields (including only one, or at most two fields) can be indexed to improve efficiency and flexibility.


8. Design a database table. This data table is used to store url data that is frequently inserted and queried.
And explains the reason for this design.
Create table url ('id' int (11) not null primary key auto_increment comment "primary key", 'url' varchar (255) not null comment "url content ", 'name' varchar (50) comment "name of the url") ENGINE = MyISAM


This is how I created it.
Frequent insertion and deletion. I think the database storage engine should use MyISAM.
It would be better to create an index on the url and name fields.

I don't want to write it easily. So many questions are on A4 paper.

Isn't that forcing me to write something simple? However, I made some low-level mistakes. I am trying to correct it.

Share some benefits with you.

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.