PHP Interview Questions.: Question: What's The Output of This Code?
PHP Interview Questions.: Question: What's The Output of This Code?
PHP Interview Questions.: Question: What's The Output of This Code?
echo $j;
echo “<br/>”
Ans; 0
01
012
0123
01234
012345
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.
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.
Cookies in PHP can be set using the setcookie() function. This must appear before the HTML tag,
Syntax:
Example: here, the cookie name sample is assigned a value jim. The cookie expires after an hour.
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:
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.
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.
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.
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?
Example:
<?php
header("Location: http://www.redirecturl.com/");
?>
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.
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
b. user ID
c. password
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
6. Which of the following delimiter syntax is PHP's default delimiter syntax
9. Php supports all four different ways of delimiting. In this context identify the false statement
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
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 ( )
c. Printf ( )