Hi everyone in this post we are going to discuss Elroi PHP Fresher Interview Questions with Answers [Also see Elroi PHP Fresher Interview Questions with Answers – PART 1,Elroi PHP Fresher Interview Questions with Answers – PART 2,Elroi PHP Fresher Interview Questions with Answers – PART 3] . Let us explore the questions brielfy;

Elroi PHP Fresher Interview Questions with Answers–PART 4

19.What is the difference between for,while,for each loop?

                     For

                  While

               For each

·    for — loops through a block of code until the counter reaches a specified number. ·    while — loops through a block of code until the condition is evaluate to true. ·    foreach — loops through a block of code for each element in an array.
·    SYNTAX: for(initialization; condition; increment){
    // Code to be executed
}
·    SYNTAX: while(condition){
    // Code to be executed
}
·    SYNTAX: foreach($array as $value){
    // Code to be executed
}
·     “for…{…}” is the loop block

·     “initialize” usually an integer; it is used to set the counter’s initial value.

·     “condition” the condition that is evaluated for each php execution. If it evaluates to true then execution of the for… loop is terminated. If it evaluates to false, the execution of the for… loop continues.

·     “increment” is used to increment the initial value of counter integer.

 

·     “while(…){…}” is the while loop block code

·     “condition” is the condition to be evaluated by the while loop

·     “block of code…” is the code to be executed if the condition gets satisfied

 

·     “foreach(…){…}” is the foreach php loop block code

·     “$array_data” is the array variable to be looped through

·     “$array_value “ is the temporary variable that holds the current array item values.

·     “block of code…” is the piece of code that operates on the array values

 

20.Write sql query for connect database in php?

The mysqli_select_db() function is used to change the default database for the connection.
SYNTAX:
mysqli_select_db(connection,dbname);
PARAMETERS:
connection-Specifies the MySQL connection to use
dbname-Specifies the default database to be used
RETURN VALUE:
TRUE on success. FALSE on failure

21.What are the CMS concepts you know?

A content management system (CMS):
It is a computer application that allows publishing, editing and modifying content, organizing, deleting as well as maintenance from a central interface. Such systems of content management provide procedures to manage workflow in a collaborative environment.

Features of CMSes:
=>SEO-friendly URLs
=>Combined and online help.
=>Group-based permission systems
=>Full template support and customizable templates
=>Easy wizard-based install and versioning procedures
=>Admin panel with multiple language support
=>Content hierarchy with unlimited depth and size
=>Minimal server requirements
=>Combined file managers
=>Combined audit logs

Functions of CMS:
=>Create, Edit, Publish, Archive web pages,Archive articles,Archive press releases,Archive blogs.
=>Add / Edit events into an Event Calendar
=>Add / Edit Inventory (products), description, product specifications, prices, photos, etc.
=>Enter, Edit, or View orders and print packing slips and invoices
=>View reports and statistics site data
=>Create and Edit system users which have different permission levels to different section(s) of the above administration

22.What are the differences between cookies and sessions? When do we use it?

Cookies are used to to track the state of the application using small files stored on the user’s computer. And sessions are used to store important information, to pass values from one page to another. The major differences between cookies and sessions are as follows:sessionc

 

                             COOKIES

                                SESSION

·    A cookie is a bit of data stored by the browser and sent to the server with every request. ·    A session is a collection of data stored on the server and associated with a given user
·    It is stored limit amount of data. It is only allowing 4kb[4096bytes] ·    It is stored unlimited amount of data.
·    It is not holding the multiple variable in cookies. ·    It is holding the multiple variable in sessions.

·    It is holding the multiple variable in sessions.

·    We can destroy cookies by

1.  Closing the browsers at the time.

2.  Setting the cookie time to expire the cookie.

 

·    We can destroy sessions by

1. Using unset() session

2. Using session_destory()

23.How to get name from one table?write query.

The mysqli_fetch_fields() function returns an array of objects that represent the fields (columns) in a result set.
SYNTAX:
mysqli_fetch_fields(result);
PARAMETERS:
result-Specifies a result set identifier returned by mysqli_query(), mysqli_store_result() or mysqli_use_result()[required parameter]
RETURN VALUE:
Returns an array of objects containing field definition information. FALSE if no info is available. The objects have the following properties:
=>name – name of the column
=>orgname – original column name (if an alias is specified)
=>table – name of table
=>orgtable – original table name (if an alias is specified)
=>max_length – maximum width of field
=>length – width of field as specified in table definition
=>charsetnr – character set number for the field
=>flags – bit-flags for the field
=>type – data type used for the field
=>decimals – for integer fields; the number of decimals used

24.What is the function use to send email?

The mail() function allows you to send emails directly from a script.
SYNTAX:
mail(to,subject,message,headers,parameters);
PARAMETERS:
=>to – Specifies the receiver / receivers of the email[Required parameter]
=>subject– Specifies the subject of the email. Note: This parameter cannot contain any newline characters[Required parameter]
=>message – Defines the message to be sent. Each line should be separated with a LF (\n). Lines should not exceed 70 characters[Required parameter]
=>headers – Specifies additional headers, like From, Cc, and Bcc. The additional headers should be separated with a CRLF (\r\n).[optional parameter.]
=>parameters – Specifies an additional parameter to the sendmail program.[optional parameter]

25.What function used for validation?

The filter_var() function filters a variable with the specified validation.
SYNTAX:
filter_var(var, filtername, options)
PARAMETERS:
=>var – The variable to be validated.[required parameter]
=>filtername – Specifies the ID or name of the filter to use.[optional parameter]
=>options – Specifies one or more flags/options to use. [optional parameter]

To be continued…

References:
https://www.guru99.com/php-loop.html
https://www.tutorialrepublic.com/php-tutorial/php-loops.php
https://www.w3schools.com/php/func_mysqli_select_db.asp
https://www.quora.com/What-is-meant-by-CMS-for-PHP
https://stackoverflow.com/questions/6339783/what-is-the-difference-between-sessions-and-cookies-in-php