You are on page 1of 9

Php Interview questions.

Question: what’s the output of this code?

for ($i=0; $i<=5; $i++)

for ($j=0; $j<=$i; $j++)

echo $j;

echo “<br/>”

Ans; 0

01

012

0123

01234

012345

Explain the difference between $message and $$message?

Answer
$message is used to store variable data. $$message can be used to store variable of a variable. Data
stored in $message is fixed while data stored in $$message can be changed dynamically.

E.g. $var1 = ‘Variable 1’


$$var1= ‘variable2’
this can be interpreted as $ Variable 1=‘variable2’;
For me to print value of both variables, I will write
$var1 $($var1)

What is a Persistent Cookie?

Cookies are used to remember the users. Content of a Persistent cookie remains unchanged even when
the browser is closed. ‘Remember me’ generally used for login is the best example for Persistent Cookie.

How to set cookies? How to reset/destroy a cookie?

Setting cookie in php:

Cookies in PHP can be set using the setcookie() function. This must appear before the HTML tag,

Syntax:

Setcookie(name, value, expire, path, domain);

Example: here, the cookie name sample is assigned a value jim. The cookie expires after an hour.

Setcookie(“sample”, “jim”, time()+3600);

Reset/destroy cookie

Cookies can be deleted either by the client or by the server. Clients can easily delete the cookies by
locating the Cookies folder on their system and deleting them. The Server can delete the cookies in two
ways:

 Reset a cookie by specifying expiry time


 Reset a cookie by specifying its name only

What the difference is between include and require?

Answer
Require() and include() are the same with respect to handling failures. However, require() results in a
fatal error and does not allow the processing of the page. i.e. include will allow the script to continue.   

Explain the differences between require and include, include_once?

Answer
Include() will include the file specified.
Include_once() will include the file only once even if the code of the file has been included before.

Require() and include() are the same with respect to handling failures. However, require() results in a
fatal error and does not allow the processing of the page.

What is the difference between the functions unlink and unset in PHP?

The function unlink() is to remove a file, where as unset() is used for destroying a variable that was
declared earlier.
unset() empties a variable or contents of file.

What is the difference between Split and Explode in PHP?

The split() function splits the string into an array using a regular expression and returns an array.
Ex: split(:India:Pakistan:Srilanka); returns an array that contains India, Pakistan, Srilanka.

The explode() function splits the string by string.


Ex: explode(and India and Pakistan and Srilanka); returns an array that contains India, Pakistan, Srilanka.

What is CAPTCHA in PHP?

Captcha are images with some characters/ digits on it. One need to type the characters or digits in the
text box for the purpose of submitting. This avoids automatic submitting by an operation by other
programs or a robot.

What are the various methods to pass data from one web page to another web page?

Answer
Different methods to pass data from one web page to another:

1. Store the data in a session variable. By storing the data, the data can be passed from one page to
another.

2. Store data in a cookie: By storing data in a persistent cookie, data can be passed from one form to
another.

3. Set the data in a hidden field and post the data using a submit button.
How many ways I can redirect a PHP page?

a. Header function in PHP redirects to a new URL

Example:

<?php 
         header("Location: http://www.redirecturl.com/"); 
?>

b. http_redirect() is also used to redirect to a new page or URL.

Syntax
void http_redirect ( [string url [, array params [, bool session = FALSE [, int status]]]] )

Here, the URL is the path of the new page. params can be some query parameters followed by whether
the session information needs to be passed and the custom response status code.

What is meant by MVC?

MODEL VIEW CONTROLLER, is a software architecture, currently considered an architectural pattern


used in software engineering.
This isolates business logic from presentation logic.

1. The Model represents the application data


2. The View renders a presentation of model data
3. The Controller handles and routes requests made by the client

What is the naming convention in cakephp?

Table names are plural and lowercased,model names are singular and CamelCased: ModelName, model
filenames are singular and underscored: model_name.php, controller names are plural and CamelCased
with *Controller* appended: ControllerNamesController, controller filenames are plural and
underscored with *controller* appended: controller_names_controller.php, associations should use the
ModelName, and the order should match the order of the foreignKeys: var $belongsTo = ‘User’; , foreign
keys should always be: table_name_in_singular_form_id: user_id (foreign key) → users (table) , many-
to-many join tables should be named:
alphabetically_first_table_plural_alphabetically_second_table_plural: tags_users , columns in many-to-
many join tables should be named like other foreign keys: tag_id and user_id , columns named
“created” and “modified” will automatically be populated correctly.

what is the first function that gets loaded from a controller in codignator.?

Index

How do you get the current controller and method name of the URL in codeignator?

echo $this->router->class;
echo $this->router->method; 

Objective Question

. In mail($param2, $param2, $param3, $param4), the $param2 contains:

a.       The message

b.      The recipient

c.       The header

d.      The subject 


 

d.      The subject


2. mysql_connect( ) does not take following parameter

a.       database host

b.      user ID

c.       password

d.      database name

d.      database name

3. Study following steps and determine the correct order

(1)   Open a connection to MySql server

(2)   Execute the SQL query

(3)   Fetch the data from query

(4)   Select database

(5)   Close Connection

a. 1, 4, 2, 3, 5

b. 4, 1, 2, 3, 5

c. 1, 5, 4, 2, 1

d. 4, 1, 3, 2, 5

a. 1, 4, 2, 3, 5
4. Which of the following is not a session function?

a.       sssion_decode

b.      session_destroy

c.       session_id

d.      session_pw

 d.      session_pw

5. When uploading a file if the UPLOAD_ERR-OK contains value 0 it means

a.       Uplaod is not successful, error occurred

b.      The file uploaded with success

c.       Uploaded file size is 0

d.      File upload progress is 0% completed 

b.      The file uploaded with success 

6.      Which of the following delimiter syntax is PHP's default delimiter syntax

a.      <? php  ?>

b.      <%   %>

c.       <?     ?>

d.      <script language="php"> </script>


a.     

9.      Php supports all four different ways of delimiting. In this context identify the false statement

a.      You can use any of the delimiting style

b.      You can use different delimiting styles in same page

c.       You can use any delimiting style but must use a single style consistently for a page

d.      Variables declared in previous blocks are remenbered on later blocks too!

c.       You can use any delimiting style but must use a single style consistently  for a page

10.      Which of following commenting is supported by Php

a.      Single line c++ syntax - //

b.      Shell syntax - #

c.       Both of above

d.       None of above

c.       Both of above


12.      Which of following function return 1 when output is successful?

a.      echo ( )

b.      print ( )

c.       both

d.      None

b.      print ( )

13.      Which of followng statement is more suitable if you want to output a blend of static text and
dynamic information stored within one or several variables?

a.      echo ( )

b.      print ( )

c.       Print f ( )

d.      None of above

c.       Printf ( )

You might also like