PHP

PHP is a widely-used open source general-purpose scripting language that is especially suited for web development. We have asked professionals to share the job interview experience and here we got some most asked questions.

Q.1 In PHP, what is PEAR?
PEAR is a framework and repository for PHP components that can be reused. PHP Extension and Application Repository (PEAR) is an acronym for PHP Extension and Application Repository. It's full with PHP code snippets and libraries of all kinds.
Q.2 What is the distinction between static and dynamic websites?
Content on static websites cannot be altered after the script has been run. Nothing on the site can be changed. It's predetermined. The content of scripts on dynamic webpages can be altered at any time. Every time a user visits or reloads the page, the content is regenerated. A dynamic website is something like Google, Yahoo, or any other search engine.
Q.3 What is the name of the PHP scripting engine?
Zend Engine 2 is the scripting engine that powers PHP.
Q.4 What is the distinction between PHP4 and PHP5?
PHP4 does not support the oops concept and instead relies on the Zend Engine 1. PHP5 uses Zend Engine 2 and supports the oops notion.
Q.5 What are some of the most popular PHP Content Management Systems (CMS)?
WordPress is a PHP and MySQL-based free and open-source content management system (CMS). It has a plug-in architecture as well as a template system. It is most commonly associated with blogging, but it also supports other types of web content, like as traditional mailing lists and forums, media displays, and online commerce. Open Source Matters, Inc. invented Joomla, a free and open-source content management system (CMS) for distributing web content. It's built on a model-view-controller web application framework that can run without a CMS. Magento is an open source E-commerce programming created by Varien Inc. that is useful for online businesses. It has a flexible measured design and is versatile, with a variety of control options that clients will find beneficial. Magento is an e-commerce platform that provides businesses with broad E-business options and a large support network.
Q.6 What are the most popular PHP frameworks?
CakePHP, CodeIgniter, Yii 2, Symfony, Zend Framework etc.
Q.7 PHP is similar to which programming language?
PHP's syntax is influenced by Perl and C.
Q.8 List some of PHP7's features.
Scalar type declarations Return type declarations Null coalescing operator (??) Spaceship operator Constant arrays using define() Anonymous classes Closure::call method Group use declaration Generator return expressions Generator delegation Space ship operator
Q.9 In PHP, what does "echo" mean?
One or more strings are output by PHP echo. It's a feature of the language, not a function. As a result, parentheses are not required. However, if you want to send more than one parameter to echo, you must use parentheses.
Q.10 What is "print" in PHP?
A string is printed by PHP. It's a feature of the language, not a function. As a result, the argument list does not require the use of parentheses. In contrast to echo, it always returns 1.
Q.11 What is the difference between the PHP commands "echo" and "print"?
Print can only output one string and always returns 1, but echo can emit one or more strings. Because echo does not return a value, it is faster than print.
Q.12 What are the different methods for defining a constant in PHP?
Constants in PHP are names or identifiers that cannot be modified while the script is running. Constants in PHP can be defined in two ways: Using the function define() The const() method is used.
Q.13 In PHP, how many different data types are there?

Data types in PHP are used to store various types of data or values. There are eight primitive data types, which are further divided into three categories:

  • Types that are scalar
  • Types of compounds
  • Types that are unique
Q.14 What are the various PHP loops?
For, while, do-while, and each are all words that can be used interchangeably.
Q.15 What is the purpose of the PHP count() function?
The count() method in PHP is used to count the total number of elements in an array or an object.
Q.16 What is the purpose of PHP's header() function?
The header() function is used to deliver a client a raw HTTP header. It must be called before the actual output is sent. You can't print any HTML element before calling this function, for example.
Q.17 Explain how to use the variable length argument function in PHP.
PHP has a function that accepts variable-length arguments. It signifies that you can send zero, one, or n arguments to the function. To accomplish this, place three ellipses (dots) before the parameter name. Since PHP 5.6, the three-dot idea has been implemented for variable-length arguments.
Q.18 What is the purpose of isset()?
The isset() method determines whether or not a variable is defined.
Q.19 Describe how PHP parameterized functions work.
Functions using parameters are known as PHP parameterized functions. Within a function, you can pass any number of parameters. Within your function, these parameters are used as variables. After the function name, they are specified inside the parentheses. The function's output is determined by the dynamic values passed in as parameters.
Q.20 Explain how to use the variable length argument function in PHP.
PHP has a function that accepts variable-length arguments. It means that you can pass zero, one, or n parameters.
Q.21 In PHP, what is an array?
An array is a type of data structure that allows you to store numerous values in a single value. It is used to organise maps of key-value pairs in PHP. It stores the data type's collection.
Q.22 How to get the length of string?
To determine the length of a string, use the strlen() method.
Q.23 In PHP, what are the techniques for submitting a form?
GET and POST are the two methods available.
Q.24 Without a submit button, how can you submit a form?
You can submit the form without clicking any submit buttons by using the JavaScript submit() function.
Q.25 Differentiate between require and include?
Both require and include are used to include a file, however include gives a warning if data is not found, whereas require sends a fatal error.
Q.26 What is the purpose of the PHP function setcookie()?
To set a cookie with an HTTP response, use the PHP setcookie() method. The $_COOKIE superglobal variable can be used to access the cookie once it has been set.
Q.27 What exactly is a session?
The PHP Engine constructs a logical object called a session to keep data consistent between HTTP requests. Sessions are used to hold temporary data so that many PHP pages can offer the same user a fully working transaction.
Q.28 What exactly is the distinction between a session and a cookie?
The fundamental distinction between a session and a cookie is that cookies are saved in text file format on the user's computer, whereas sessions are stored on the server. Cookies, on the other hand, cannot hold many variables; however, Session can. A cookie can be set to expire at any time, but a session is only active as long as the browser is open.
Q.29 In PHP, how do you delete a file?
To delete a file in PHP, use the unlink() method.
Q.30 What is the command-line approach for running a PHP script?
Simply run the PHP command line interface (CLI) and enter the file name of the script to run as shown below.
Q.31 In PHP, how do you send email?
In PHP, the mail() function is used to send an email.
Q.32 How can we speed up the execution of a PHP script?
The maximum execution time for PHP scripts is set to 30 seconds by default. If a script takes more than 30 seconds to complete, PHP will terminate it and return an error. The max execution time directive in the php.ini file can be changed to adjust the script execution time. The set time limit function resets the timeout counter to zero when a script is called. It means that if the default timer is set to 30 seconds and the method set time limit() is set to 20 seconds, the script will run for 45 seconds. If 0sec is given in this function, the script will run forever.
Q.33 In PHP, what is htaccess?
The.htaccess file is an Apache server configuration file. Directives in Apache configuration files such as.htaccess and httpd.conf can be used to adjust configuration parameters.
Q.34 Describe the function explode() in PHP.
The explode() method in PHP converts a string to an array.
Q.35 Describe the split() method in PHP.
The PHP split() function uses a regular expression to split a string into an array.
Q.36 What are the functions include() and require()?
Include() is a PHP function that inserts data from one PHP file into another PHP file. If an error occurs, the include() method issues a warning but does not terminate the script's execution; it will continue to run. The Require() function can also be used to transfer data from one PHP file to another. If any errors occur, the need() method issues a warning and a fatal error, and the script is terminated.
Q.37 What does the term "persistent cookie" mean?
A persistent cookie is one that is saved in the browser's cookie file indefinitely. Cookies are transitory by default and are deleted when we exit the browser.
Q.38 What is the purpose of the imagetypes() function?
imagetypes() returns the supported image formats and types in the current version of GD-PHP.
Q.39 What is type casting in PHP?
Implicit and Explicit Casting
Q.40 Where is session data stored PHP?
PHP Default Session Storage (File System), In PHP, by default session data is stored in files on the server. Each file is named after a cookie that is stored on the client computer.
Q.41 Which function is used to convert an array into a string?
implode() function is used to convert an array into a string.
Q.42 What is cookies in PHP with example?
A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user's computer. ... For example, if a cookie was sent with the name "client", a variable is automatically created called $client, containing the cookie value. Note: The setcookie() function must appear BEFORE the tag.
Q.43 What is the simplest method of finding sum of all the elements of an array?
array_sum function is the simplest method of finding sum of all the elements of an array.
Q.44 What is the difference between print() and echo()?
print() can be used as part of an expression, while echo() can’ t.
Q.45

Find the output of the following script.

function sort_my_array($array){         
return sort ($array );    }       
$a1 =  array(3, 2, 1);          
var_dump( sort_my_array(&$a1)) ;

It will give you the following output.

Error

Q.46

Find the output of following script.

$array  = array('a','b','c','d');
array_walk  ($array,  'glue');
echo $result;

It will give you the following output.

abcd

Q.47

Find the output of following script.

$array = array( 1, 2, 3,5,8,13,21,34, 55);     
$sum =  0;
for ($i  =  0; $i<5;$i++) 
{ 
$sum +=  $array[$array[$i]];
} 
echo $sum;

It will give you the following output.

78

Q.48

Find the output of following script. 

$x = 0;
if($x++)
print "hi";   
else  
print "how are u";

The output will be

how are you

Q.49

Find the output of following script. 

$x = 0;
if($x++)
print "hi";   
else  
print "how are u";

The output will be

how are you

Q.50 How would you store order number (34) in an 'OrderCookie'?
setcookie('OrderCookie',34);
Q.51 What happens when a form submitted to a PHP script contains two elements with the same name?
Value of second element overwrites the first in specific superglobal array
Q.52

Find the output of following script.

echo 'Testing ' . 1  +  2 . '45';

It will give you the following output.

245

Q.53

1. Find the output of following script.

$array1  = array(0.1  =>  'a', 0.2  =>  'b'); 
echo count  ($array1) ;

The output will be 1.

Get Govt. Certified Take Test