30 plus interview question & answer on PHP and laravel ?

30 plus interview question & answer on PHP and laravel ?

30 plus interview question & answer on PHP and laravel ?

30 plus interview question & answer on PHP and laravel ?

Most of the interviewer are make simple mistake in interview board to give some common question. Today I will discuss 30 plus interview question and answer for web and software developer who work on php and laravel profession.

Q. What is PHP?

Stands for "Hypertext Preprocessor." It was originally created by Rasmus Lerdorf in 1994

Q: What does $GLOBALS mean?

   $GLOBALS is associative array including references to all variables which are currently defined in the global scope of the script.

Q: What does $_SERVER mean?

   $_SERVER is an array including information created by the web server such as paths, headers, and script locations.

Q: What does $_FILES means?

  $_FILES is an associative array composed of items sent to the current script via the HTTP POST method.

PEAR (PHP Extension and Application Repository) is a framework and repository for reusable PHP components. PEAR is a code repository containing all kinds of php code snippets and libraries.

Q: The only differences are echo and print

1.   echo does not return a value whereas print does return a value of 1 (this enables print to be used in expressions).

2.   echo can accept multiple parameters (although such usage is rare) while print can only take a single argument.


Q: What is the difference between include_once() and require_once(), which one would you use in circumstances where you need to connect to a database, and why?

include_once() or include allows a file to be included, and in cases where the file is missing or has the wrong name, we receive an error message and execution will still continue regardless.
On the other hand, require_once() or require would be suitable in cases where a file needs to be included once and if it is missing or has a wrong name then we receive a fatal error and the execution of the program stops.

Q: How can you tell if a number is even or odd without using any condition or loop?

$arr=array("0"=>"Even","1"=>"Odd");
$check=13;
echo
"Your number is: ".$arr[$check%2];

Q: What does the follow code echo?

$a = "PHP";
$a = $a + 1;
echo $a;

Note, in PHP 7.2 this throws a warning that a non-numeric value is encountered on the line and does not do the conversion to the int, so it echoes PHP instead.


Q: How many error are basically occurs in php?

Basically there are four types of errors in PHP, which are as follows:

1.   Parse Error (Syntax Error) missing comma;

<?php
echo "Cat";
echo "Dog" // give an parse error
echo "Lion";
?>


2.   Fatal Error. : If you are trying to access the undefined functions, then the output is a fatal error

<?php
function fun1(){
{
echo "Vineet Saini";
}
fun2(); // undefined function
}
fun2(); // undefined function
echo "Fatal Error !!";
?>


3.   Warning Error.: include a missing file or using the incorrect number of parameters in a function.

<?php
echo "Warning Error!!";
include ("Welcome.php");
?>

4. Notice Errors: Notice that an error is the same as a warning error i.e. in the notice error execution of the script does not stop. Notice that the error occurs when you try to access the undefined variable, then produce a notice error.

<?php
$a="Vineet
kumar saini";
echo "Notice Error !!";
echo $b;
?>


Q: how many array function in php?
There are three types of array in PHP:


Indexed array: The array which contains numeric index.

Syntax:
array( val1, val2, val3, ... )

Associative array: The array which contains name as keys.

Syntax:
array( key=>val, key=>val, key=>value, ... )


Multidimensional array: The array which contains one or more arrays.

Syntax:
array( array( val11, val12, ...)
      array( val21, val22, ...)
      ... )

Sort Functions For Arrays

sort() - sort arrays in ascending order
rsort() - sort arrays in descending order
asort() - sort associative arrays in ascending order, according to the value
ksort() - sort associative arrays in ascending order, according to the key
arsort() - sort associative arrays in descending order, according to the value
krsort() - sort associative arrays in descending order, according to the key

Q. How many PHP Conditional Statements?
if statement - executes some code if one condition is true
if...else statement - executes some code if a condition is true and another code if that condition is false
if...elseif...else statement - executes different codes for more than two conditions
switch statement - selects one of many blocks of code to be executed

<?php
$t = date("H");
if ($t < "10") {
    echo "Have a good morning!";
} elseif ($t < "20") {
    echo "Have a good day!";
} else {
    echo "Have a good night!";
}
?>
Switch condition

<?php
$favcolor = "green";
switch ($favcolor) {
    case
"red":
     
echo "Your favorite color is red!";
     
break;
    case
"blue":
     
echo "Your favorite color is blue!";
     
break;
    case
"green":
     
echo "Your favorite color is green!";
     
break;
 
default:
     
echo "Your favorite color is neither red, blue, nor green!";
}
?>

Q.How many PHP Loops?


while - loops through a block of code as long as the specified condition is true
do...while - loops through a block of code once, and then repeats the loop as long as the specified condition is true
for - loops through a block of code a specified number of times
foreach - loops through a block of code for each element in an array


<?php
$x = 1;
while($x <= 5)
{
    echo "The number is: $x <br>";
    $x++; // Increase the loop counter value by 1 for each iteration
$x+=10; //Increase the
loop counter value by 10 for each iteration
}
?>

#do...while

<?php
$x = 6;
do {
    echo "The number is: $x <br>";
    $x++;
} while ($x <= 5);
?>
# for loop
<?php
for ($x = 0; $x <= 100; $x+=10) {
    echo "The number is: $x <br>";
}
?>
#foreach loop


<?php
$colors = array("red", "green", "blue", "yellow");
foreach ($colors as $value) {
  echo "$value <br>";
}
?>

Function: A function is a block of statements that can be used repeatedly in a program.

<?php
function familyName($fname, $year) {
    echo "$fname Refsnes. Born in $year
<br>";
}
familyName("Hege", "1975");
familyName("Stale", "1978");
familyName("Kai Jim", "1983");
?>
Output
Hege
Refsnes. Born in 1975
Stale Refsnes. Born in 1978
Kai Jim Refsnes. Born in 1983


*************************** (Laravel interview question) ***************************

Q. What is Laravel ? 

Laravel is a web application framework with expressive, elegant syntax. We've already laid the foundation. created by Taylor Otwell

Q. What is Framework ?:

Framework may also include code libraries, a compiler, and other programs used in the software development process.

Q. what is Middleware?

Middleware provide a convenient mechanism for filtering HTTP requests entering your application. For example, Laravel includes a middleware that verifies the user of your application is authenticated.

Q. What is (CSRF) ?:

CSRF attacks. Cross-site request forgeries are a type of malicious exploit whereby unauthorized commands are performed on behalf of an authenticated user.

Q. What is Controllers?

Controllers are meant to group associated request handling logic within a single class. In your Laravel project, they are stored in the app/Http/Controllers' directory. The full form of MVC is Model View Controller, which act as directing traffic among the Views and the Models.

Q. What is Eloquent ORM ?

The Eloquent ORM included with Laravel provides Active Record implementation for working with your database. Each database table has a corresponding "Model" which is used to interact with that table. Models allow you to query for data in your tables, as well as insert new records into the table.


----Follow our next part for more interview question...

Related Jobs

Comments


  • 30 plus interview question
  • php interview question
  • laravel interview question
  • 30 plus important interview question