search
HomeBackend DevelopmentPHP TutorialPHP programmer interview sharing_PHP tutorial

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";

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;
}

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

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. 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


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...
Statement
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
PHP Performance Tuning for High Traffic WebsitesPHP Performance Tuning for High Traffic WebsitesMay 14, 2025 am 12:13 AM

ThesecrettokeepingaPHP-poweredwebsiterunningsmoothlyunderheavyloadinvolvesseveralkeystrategies:1)ImplementopcodecachingwithOPcachetoreducescriptexecutiontime,2)UsedatabasequerycachingwithRedistolessendatabaseload,3)LeverageCDNslikeCloudflareforservin

Dependency Injection in PHP: Code Examples for BeginnersDependency Injection in PHP: Code Examples for BeginnersMay 14, 2025 am 12:08 AM

You should care about DependencyInjection(DI) because it makes your code clearer and easier to maintain. 1) DI makes it more modular by decoupling classes, 2) improves the convenience of testing and code flexibility, 3) Use DI containers to manage complex dependencies, but pay attention to performance impact and circular dependencies, 4) The best practice is to rely on abstract interfaces to achieve loose coupling.

PHP Performance: is it possible to optimize the application?PHP Performance: is it possible to optimize the application?May 14, 2025 am 12:04 AM

Yes,optimizingaPHPapplicationispossibleandessential.1)ImplementcachingusingAPCutoreducedatabaseload.2)Optimizedatabaseswithindexing,efficientqueries,andconnectionpooling.3)Enhancecodewithbuilt-infunctions,avoidingglobalvariables,andusingopcodecaching

PHP Performance Optimization: The Ultimate GuidePHP Performance Optimization: The Ultimate GuideMay 14, 2025 am 12:02 AM

ThekeystrategiestosignificantlyboostPHPapplicationperformanceare:1)UseopcodecachinglikeOPcachetoreduceexecutiontime,2)Optimizedatabaseinteractionswithpreparedstatementsandproperindexing,3)ConfigurewebserverslikeNginxwithPHP-FPMforbetterperformance,4)

PHP Dependency Injection Container: A Quick StartPHP Dependency Injection Container: A Quick StartMay 13, 2025 am 12:11 AM

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Dependency Injection vs. Service Locator in PHPDependency Injection vs. Service Locator in PHPMay 13, 2025 am 12:10 AM

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHP performance optimization strategies.PHP performance optimization strategies.May 13, 2025 am 12:06 AM

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHP Email Validation: Ensuring Emails Are Sent CorrectlyPHP Email Validation: Ensuring Emails Are Sent CorrectlyMay 13, 2025 am 12:06 AM

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools