PHP

Interview Questions on PHP

11. How to create session variable?

Ex :-  
session_start();
$_SESSION["session_var1"] = "value1";
$_SESSION["session_var2"] = " value2";

12. How to destroy the session variable?

unset ($_SESSION['varname']);

13. What is the difference between cookie and session variables?

Cookies will be created and stored in browser.
Sessions will be created by Server and maintained bybrowser.

14. Which one is best to use cookie or session variable?

Sessions
Reason:-
Sessions are stored on the server, which means clients do not have access to the information you store about them. You do not need to send the data for each request.
On the other hand, Cookies maintained in browser and data stored in Cookies is transmitted in full with each page request.

15. How to create object for a class?

By using new operator.
Ex :- 
Class Foo{
   //data members
}
$foo = new Foo;

16. How to call a function of a class in php?

By using -> operator
Ex :- 
Class Foo{
   //data members
     public function newTest(){
          $this->bigTest();
          $this->smallTest();
     }
}
$foo = new Foo;
$foo->newTest();

17. How to include other php file code?

By using include
Ex :- 
<?php
include otherfilename.php';
?>

18. What are the most popular php frame works?

• Laravel
• CakePHP
• Zend Framework
• Phalcon
• Slim
• Yii

19. What is the difference b/w echo and print statement?

echo can take multiple parameters (although such usage is rare) while 
print can take one argument.

20. How to concat strings in php?

By using . operator
Ex :- 
<?php
echo "thr"."ee";           //prints the string "three"
echo "twe" . "lve";        //prints the string "twelve"
echo 1 . 2;                //prints the string "12"
echo 1.2;                  //prints the number 1.2
echo 1+2;                  //prints the number 3
?>

www.000webhost.com