Hi everyone, in this post we are going to discuss Techaffinity PHP Fresher Interview Questions. Let us discuss the questions briefly with their answers in this post;
1. What is ksort?
The ksort() function is an inbuilt function which is used to sort an array in ascending order according to its key values. The relation between the indices and the values are maintained in this type of sorting.
Syntax:
bool ksort( $array, $sorting_type )
Parameters:
This function accepts two parameters as mentioned above and described below:
I.$array: This mandatory parameter specifies the array which needs to be sorted.
II.$sorting_type: This is an optional parameter. The various sorting types are discussed below:
=>SORT_REGULAR: To compare the items normally.
=>SORT_NUMERIC: To compare the items numerically.
=>SORT_STRING: To compare the items as a string.
=>SORT_LOCALE_STRING: To compare the items as string, based on current locale.
Return Value:
This function returns True on success or False on failure.
2. How do you delete a file in php system?
The delete() function deletes a file.
This function returns TRUE on success and FALSE on failure.
Syntax: delete(file)
Parameter: file (compulsorily required to specify the file to delete)
Sample code:
<?php
echo delete(“target.txt”);
?>
Sample output:
1
3. How to find the string length?
You can use the strlen() to get the length of a string.
It takes a string as a parameter and returns its length.
It calculates the length of the string including all the whitespaces and special characters.
Syntax: strlen($string)
Parameters: The strlen() fucntion accepts only one mandatory parameter $string which represents the string whose length is to be returned.
Return Value: The strlen() function return the length of the string on success, and 0 if the string is empty.
Sample code:
<?php
// PHP program to find the
// length of a given string
$str = “ABDUL KALAM”;
// prints the length of the string
// including the space
echo strlen($str);
?>
Sample output:
11
4. What is the difference between Mysql and MySqli?
Mysql and MySqli both are the PHP based extension which we used to make connection with our database and handle database query through PHP. It makes easier to communicate with database and handle all database related queries, There is large set of the function available in these extensions.
The differences between the two is as follows:
MySQL |
MySQLi |
MySQL extension added in PHP version 2.0. and deprecated as of PHP 5.5.0. | MySQLi extension added in PHP 5.5 and will work on MySQL 4.1.3 or above. |
Does not support prepared statements. | MySQLi supports prepared statements |
MySQL provides the procedural interface. | MySQLi provides both procedural and object-oriented interface. |
MySQL extension does not support stored procedure | MySQLi supports store procedure. |
MySQL extension lags in security and other special features, comparatively | MySQLi extension is with enhanced security and improved debugging. |
Transactions are handled by SQL queries only. | MySQLi supports transactions through API. |
5. What is a session?
=> A PHP session is an alternative way to make data available over the various pages of an entire website.
=> A session creates a file in a temporary directory on the server where registered session variables and their values are stored.
=> This data will be available to all pages on the site during that visit.
Starting PHP Sessions:
To start a session, you must use the function session_start().
To set session variables, you will need to apply a global variable $_SESSION.
The session_start() function must be the very first thing in your document. Before any HTML tags.
Session data in form of variables must be individually retrieved (session_start()).
Destroying PHP Sessions:
Using session_unset() will remove all of the global variable, while session_destroy() will destroy the session entirely (however the effect of both is similar).
To be continued…
References:
https://www.geeksforgeeks.org/php-ksort-function/
https://www.w3schools.com/php/func_filesystem_delete.asp
https://secure.php.net/manual/en/function.strlen.php
https://phppot.com/php/mysql-vs-mysqli-in-php/
https://www.bitdegree.org/learn/php-sessions/