Breaking News
You are here: Home / Paper Solutions / SEM-5 / PHP MYSQL / PHP Paper Solution – October/November – 2011

PHP Paper Solution – October/November – 2011

PHP Paper Solution – October/November – 2011

Q1: Answer the following in short

PHP Paper Solution

(a) What is the difference between $name and $$name ?

Ans: $name is a simple variable whereas $$name is a reference variable.

$$name is a variable it’s name is stored in $name.

Example:

$name = 'test';
$$name = 'xyz';

$test='xyz';

 

(b) Explain the Define()?
Ans: It is same in c language that it also used to define constant value to the variable
Syntax:

                define(name,value,case_sensitive=false)

Name: Required , Specifies the name of the constant
Value: Required, Specifies the value of the constant
case_sensitive: It is optional , It Specifies whether the constant name should be case_insensitive

  • The defined () function check whether a constant exits
  • Return True if the constant exits or false otherwise defined

 

(c) What is different between single quote String literal & double quote String literal?
Ans:

Single Quoted Literal:-
The simplest way to specify the a string into enclose it in single quote
e.g:- ‘the character’
In the echo statement the single quote used to display on the browser windows but variable not expanded occur in the single quoted
               

e.g :

$a=10;
echo ‘the number of a = $a’;
o/p the number of a = $a

Double Quoted Literal:-
        It the String is enclosed in double quoted(“”)
e.g “The String”

It is expanded the occur the variable in double quoted literal

e.g

$a=10;
echo “the number of a = $a”;
o/p the number of a = 10

 

(d)Explain the terms Die &Return?
Ans :

Die :-

  • The die and Exit statement both are same working
  • The Die statement terminated execution of the script
  • It prints status just before exiting
  • The status is an integer
  • Status range is 0 to 254
  • The status 0 is used to terminated the program successfully

    Return:-

  • The return statement immediately end execution of the current function
  • The return statement its argument as the value of the function call
  • Return statement will also end the execution of an eval() statement of an or Script file

 

 (e) What are default session time and path?

Ans:

  • default session time in PHP is 1440 seconds or 24 minutes
  • Default session save path id temporary folder /tmp.

 

(f) What is use of isset() function?

Ans:

In php isset function comes in handy isset is a function that take any variable you want to use and check to see if  it has been set. That is, it has already been assigned a value

eg:

<?php
     if(isset ($_session[‘views’]))
        $_session[‘views’]=$_session[‘views’]+1;
else
       $_session[‘views’]=1;
?>

 

(g)What is different between function unlink and unset?
Ans :

Unset () Function:- it is mainly used to free the specified session variable

e.g

<?php
    unset($_session[‘views’) 
?>

 

Unlink() Function :- Its mainly used delete the file
Syntax :

unlink(filename,context)

 

Q2: Answer the following

(a) Discuss different Data types in php?

Ans: A Data types refers to the type of data a variable can store. PHP has eight(8) different data types.

  1. Integer number
  2. Floating point number
  3. Strings
  4. Booleans
  5. Arrays
  6. Objects
  7. Resources
  8. Null

 

Integer

  • The integer data types is use to specify a numeric value without a factorial comment.
  • You can declare as given bellow

Integer $varabile;

$variable=10;

 

Real number

  • It is also known as floating number or floating point number. It is whole number and has fractions such as 1.22, 2.45, 100.765 etc.
  • Some examples of valid floating point numbers include:
  • 3.14
  • 0.001
  • -1.234
  • 0.314E2 // 31.4
  • 1.234E-5//0.00001234
  • -3.45E-3//-0.00345

 

Boolean

  • Boolean values are true or false, also 0 and empty string evaluates to false, and any numeric value rather than zero, or a string that is not empty evaluates to true.
  • You can declare as given bellow.
    • Boolean $variables;
    • Where Boolean denotes the type of the variable.

 

Strings

  • String values are sequence of characters, include in a single quotes, for example,
  • $strl = “this is a string data type variable”;
  • A string literal can be specified in four different ways:
  1. Single quoted
  2. Double quoted
  3. Heredoc quoted
  4. Now doc quoted

        

Arrays

  • An array in PHP is actually ordered map. A map is a type that associates values to keys.
  • This type is optimized for several different uses; it can be treated as an array, list (vector), hash table (an implementation of a map), Dictionary, collection, stack, queue, and probably more.
  • As array values can be other arrays, trees and multidimensional arrays are also possible.

 

Resource

  • Resources are not actual data type, but the storing of a reference to functions and resources external to PHP.
  • The most common example of using the resources data type is a data base call.

 

Null

  • Null is a special data type which can only have one value, which is itself.
  • Which is to say, null is not only a data type, but also a key word literal. A variable of data type null is a variable that has no value assigned to it

 

OR

 

Q2:  Answer the following

 

(a)Discuss different types of tables in mysql.

  • Mysql  supports  various types of  tables  or  storage  engines  to allow  you To optimize  your  database.
  • The  table  types  are  available  in MYSQL are:

1.   ISAM

2.   MYISAM

3.   InnoDB

4.   BerkleyDB(BDB)

5.   MERGE

6.   HEAP

 

1.  ISAM :

  • ISAM had been  deprecated  and  removed  from  version  5.x.  all of
  • It functionality entire replace by MYISAM. ISAM table has a hard Size 4GB and is  not  portable.

 

2. MYISAM: 

  • MYISAM  table  type   is  default  when  you  create table.MYISAM
  • Table  work  very  fast  but  not  transaction-safe.The  size  of MYISAM  table  depends  on  the  operating  system  and  the data File  is  portable from  system  to  system.
  • With  MYISAM  table type you  can  have  64 keys  per  table  and maximum  key  length  of 1024 bytes.

 

3. InnoDB:

  • Different  from  MYISAM  table  type, innoDB table  are  transaction safe And  supports  row-level  locking.
  • foreign  keys  are  supported  in innoDB Tables.
  • The data   file  of  Innodb  table  can  be stored  in more  than one  File  so the  size  of  table  depends  on  the  disk  space.
  • like  the  MYISAM Table  type, data  file  of  InnoDB   is  portable  from  system  to  system.
  • The   disadvantage  of  InnoDB in comparison  with  MyISAM  is  it  take More  disk  space.

 

 4. BDB:

  • BDB  is  similar  to  InnoDB  in  transaction  safe.
  • It supports page level locking But data file  are  not  portable.

 

5. MERGE: 

  • Merge  table  type  is added  to  treat  multiple MYISAM  tables  as  a  single Table  so  it  remove  the  size  limitation  from  MYISAM  tables.

 

6.  HEAP: 

  • Heap table is stored in memory  so  it is  the  fastest  one. Because  of  storage Mechanism, the  data  will  be  lost  when  the  power  failure  and  sometime  it cause  the  server  run  out  of  memory.
  • Heap tables  do  not  supports   columns with AUTO_INCREMENT, BLOB  and TEXT characteristics.

 

(b)Discuss different loops available in php.

  • Loops in PHP are used to execute the same block of code a specified number of times, or while a specified condition is true.
  • PHP supports four loop types.

1.   for

2.   while

3.   do…While

4.   for each

 

1. for loop:-

  • The for statements is used when you know how many times you want To execute a statement or block of statement.

Syntax:

for(initialization; condition; increment)

{

Code to be executed;

}

 

Example:

<?php
      $test =5;
      For ($i=1 i<=5 ; i++)
      {
       echo   $i;”<br/>”;
      }
?>

 

Output:

1

2

3

4

5

 

2. While loop:

  • The while loop execute a block  of code  while  a condition is true.

 

Syntax:

while(condition){

Code to be executed;

}

Example:

<?php
   $i =0;
   $num  =50;             
   While($i <10)
   {
    $sum--;
    $i++;
   }
  echo(“loop stopped at  i=$i and num =$sum”);
?>

 

Output:

I = 1;

Num = 40

 

3. Do…while loop:

  • The do…while statement will execute a block of code at least Once it then will repeat the loop as long as a condition is true.

 

Syntax:

do

{

Code to be executed;

}while(condition);

 

Example:

<?php

   $i=0;

   $num=50;

  While($i < 10)
  {
        $sum—;

        $i++;
 }

  echo(“loop stopped at I =$i  and num =$num”);

?>

 

Output:

Loop stop at I = 10

 

4. for each loop:

  • The foreach statement is used to loop through arrays. for each Pass the  value  of  the   current  array  element  is  assigned to $value  and  the  array  pointer is  moved  by  one  and  in  the next  pass  next Element will  be  processed.

Syntax:

foreach(array   as  value)

{

Code to be executed;

}

 

Example:

<?php

        $array  = array(1,2,3,4,5);

        foreach($array  as  $value)
        {

                Echo”value  is  $value <br/>;

        }

        ?>

 

Output:

Value is 1

Value is 2

Value is 3

Value is 4

Value is 5

 

Q3: Answer the following

 

(a): Discuss any 5 functions of File handling.

Ans : The filesystem functions are used to access and manipulate the filesystem PHP provides you all the possible functions you may need to manipulate a file.

 

1) Fopen() function :

The fopen() function opens a file or URL.

 

Syntax:

fopen(filename,mode)

 

Mode:  

r = Read only

r+ = Read / Write

w = Write only

w+ = Read / Write

a = Append

x = Create a new file.

 

Example:-

<?php

                $file=fopen("test.txt","r");

                $file=fopen("E:/Sonu/test.txt","r");

 ?>

 

2) Fread() function :

The fread() reads from an open file. The function will stop at the end of the file or when it reaches the specified length,whichever comes first.

 

Syntax:

fread(file,length)

 

Example1:-

<?php

     $file=fopen("test.txt","r")
     fread($file,"10");
     fclose($file);

?>

 

Example2:-

     <?php

                $file=fopen("test.txt","r");

                fread($file,filesize("test.txt"));             

          // for read entire file...

                fclose($file);

        ?>

 

3) Fwrite() function :

The fwrite() writes to an open file. The function will stop at the end of the file or when it reaches the specified length,whichever comes first.

 

Syntax:

fwrite(file,string,length)

length is optional..

 

Example:-

 <?php

                $file=fopen("test.txt","r+");

                fwrite($file,"Hello");

                fclose($file);

        ?>

 

4) Fclose() function :

The fclose() function closes an open file. The function returns TRUE on success or FALSE on failure.

 

Syntax:

fclose(file)

 

Example:

<?php

                $file=fopen("test.txt","r");

                // Some code to be executed

                fclose($file);

                echo ”the file is closed ”

        ?>

 

Output:

                        The file is closed

                       

5) File_exists() function :

The file_exists() function checks whether or not a file or directory exists.

 

Syntax:

file_exists(path)

 

Example:-

<?php

           echo file_exists("test.txt");

        ?>

 

Output:

The output of the code will be: 1

 

 

OR

 (A)What is session? Where you will use it in web programming?

 A PHP session variable is used to store information about, or change settings for a user session. Session variables hold information about one single user, and are available to all pages in one application.

 

PHP Session Variables

When you are working with an application, you open it, do some changes and then you close it. This is much like a Session. The computer knows who you are. It knows when you start the application and when you end. But on the internet there is one problem: the web server does not know who you are and what you do because the HTTP address doesn’t maintain state.

 

A PHP session solves this problem by allowing you to store user information on the server for later use (i.e. username, shopping items, etc). However, session information is temporary and will be deleted after the user has left the website. If you need a permanent storage you may want to store the data in a database.

 

Sessions work by creating a unique id (UID) for each visitor and store variables based on this UID. The UID is either stored in a cookie or is propagated in the URL.

 

 Why Use Session?

As a website becomes more sophisticated, so must the code that backs it. When you get to a stage where your website needs to pass along user data from one page to another, it might be time to start thinking about using PHP sessions.

 

A normal HTML website will not pass data from one page to another. In other words, all information is forgotten when a new page is loaded. This makes it quite a problem for tasks like a shopping cart, which requires data (the user’s selected product) to be remembered from one page to the next.

 

 (b) Write a php script to list data in table from database.

 

<?php

$cn=mysql_connect("localhost","root","");

mysql_select_db("test_db",$cn);

?>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Database Sample Application</title>

</head>

<body>

<h1 align="center">My First Database Application</h1>

<hr size="3"  color="#FF0000"/>

    <table align="center">

      <tr bgcolor="#CCCCCC">

            <td>Name</td>

            <td>Age</td>

        </tr>

        <?php

            $query=mysql_query("select * from student");

            while($rs=mysql_fetch_object($query))

            {

            ?>

      <tr>

            <td><?php echo $rs->s_name;?></td>

            <td><?php echo $rs->s_age;?></td>

        </tr>       

        <?php
            }
            ?>

    </table>

</body>

</html>

 

OUTPUT:

myfirstdatabase_app

 

 

Q.3(B)Write a php script to list databases available in mysql database server.

 

<?php

      $con=mysql_connect("localhost","root","") or die ('Connection fail..');

      $result = mysql_list_dbs($con);

      while ($row = (mysql_fetch_object($result)))

      {

            echo $row->Database."<br>";

      }

      mysql_close($con);

?>

OUTPUT:-

information_schema
mysql
performance_schema
test
test_db

 

Q3(C) How Comments are given in php code?

Ans :

  • While there is only one type of comment in HTML, PHP has two types.
  • The first type we will discuss is the single line comment. The single line comment tells the interpreter to ignore everything that occurs on that line to the right of the comment.
  • for single line comment type “//” or “#” and all text to the right will be ignored by PHP interpreter.

 

PHP Code:

<?php

echo "Hello World!"; // This will print out Hello World!

// echo "Hello India";

# echo "Hello India";

?>

Similar to the HTML comment, the multi-line PHP comment can be used to comment out large blocks of code or writing multiple line comments. The multiple line PHP comment begins with ” /* ” and ends with ” */ “.

<?php

echo "Hello World!";

/* echo "Hello India";

echo "Hello World";

*/

?>

Q4: Answer the following

 

(a)  List all input elements. Explain any two with example.

Ans: Input elements are as follows:

There are many input elements for INPUT type like

1. Textbox

2. Hidden fields

3. Password fields

4. Checkbox

5. Radio Button

6. Image

7. Button

8. Submit

9. Reset

 

*EXPLAINATION:-

Textbox

Description  textboxA single line text box can be used to collect single line input from user like name, email, phone number etc.
Example <input type=”text” name=”txtname” value=”Enter Name” maxlength=”20″ />

Attributes

type=”text” Type attribute is used to define a type of the html input.Here type=”text” so one Textbox will be generated.
Name Used to assign the name to the Textbox.
Value text you give as value will be displayed by default in the text box.here in our example default text will be “Enter Name”.
maxlength Specifies the maximum number of characters the user can enter into the text box.Here in out example you can enter only 20 characters in the textbox.

 

Textarea

Description  text_areaA single line text box can be used to collect multi line input from user like address, feedback, description , comments etc.
Example
<textarea name="feedback" rows="10" cols="40">   default text here.   </textarea>

Attributes

Name Used to assign the name to the textarea.
Rows Specifies the number of rows in textarea. here in our example number of rows is 10.
Cols Specifies the number of columns in textarea. here in our example number of columnsis 40.

 

 

OR

(a) How array are created in PHP? Discuss any three sorting Function of array?

 

Ans .

  • Arrays provide a way to store much larger amounts of data without having many separate named variables.
  • If a normal variable where data can be stored, a simple array is like a row where lots of data can be stored.
  • Normal variables have names like $test
  • An array variable is named with square brackets. Here is an example $test[]
  • Each element in the array has its own index so that it can be easily accessed.
  • You can use it either as a simple c like array or as an associative array.
  • Here array indices are enclosed into [] rather than {}.
  • Rather than having a fixed number of slots, php creates array slots as new elements are added to the array.
  • You can assign any type for keys and values. Such as string, float ,integer etc.
  • In PHP, there are three kinds of arrays:

o  Numeric array – An array with a numeric index

o  Associative array – An array where each ID key is associated with a value

o  Multidimensional array  An array containing one or more arrays

 

 

1.Numeric array

  • A numeric array stores each array element with a numeric index.
  • There are two methods to create a numeric array.

 

1. In the following example the index are automatically assigned (the index starts at 0):

<?php

$names=array(“Juned Sir”,” Nishant”,” Karishma”,” Mayur”);

?>

2. In the following example we assign the index manually:

<?php

$names[0]=”JunedSir”;
$names[1]=”Nishant”;
$names[2]=”Karishma”;
$names[3]=”Mayur”;

?>

 

2.Associative array :

  • An associative array, each ID key is associated with a value.
  • When storing data about specific named values, a numerical array is not always the best way to do it.
  • With associative arrays we can use the values as keys and assign values to them.

 

<?php

$ages = array(“Nishant”=>20, “Mayur”=>19, “Karishma”=>21);

?>

 

3.Multidimensional array

  • In a multidimensional array, each element in the main array can also be an array.

And each element in the sub-array can be an array, and so on.

<?php

$faculties=array

  (
  "BCA"=>array
  (
  "JunedSir",
  "MaulikSir",
  "KirtiMadam"
  ),
  "BBA"=>array
  (
  "ShamaMadam"
  ),
  "BCOM"=>array
  (
  "NehaMadam",
  "BhumikaMedam",
  "RadhikaMadam"
  )
  );

?>

The array above would look like this if written to the output:

<?php

Array
(
[BCA] => Array
  (
  [0] => Juned Sir
  [1] => Maulik Sir
  [2] => Kirti Madam
  )
[BBA] => Array
  (
  [0] => Shama Madam
  )
[BCOM] => Array
  (
  [0] => Neha Madam
  [1] => Bhumika Medam
  [2] => Radhika Madam
  )
)

?>

Three sorting functions of an array :

1) sort()

  • Sort an array by the values.

Syntax :

                    sort(array)

Example: 

<?php

$fruits = array("lemon", "orange", "banana", "apple");
sort($fruits);

print_r($fruits);

?>
The output of the code above will be:

Array ( [0] => apple [1] => banana [2] => lemon [3] => orange ) 

2) rsort()

  • sorts an array by the values in reverse order.

Syntax:

                   rsort(array) 

Example:

<?php

$fruits = array("lemon", "orange", "banana", "apple");
rsort($fruits);

print_r($fruits);

?>

The output of the code above will be:

Array ( [0] => orange [1] => lemon [2] => banana [3] => apple ) 

 

3) asort()

  • The asort() function sorts an array by the values. The values keep their original keys.

 Syntax:

                   asort(array)

Example:

<?php

$fruits = array("lemon", "orange", "banana", "apple");
asort($fruits);

print_r($fruits);

?>

The output of the code above will be:

Array ( [3] => apple [2] => banana [0] => lemon [1] => orange ) 

 

4) arsort()

  • sorts an array by the values in reverse order. The values keep their original keys.

 Syntax:

                   arsort(array,sorttype) 

Example:

<?php

$fruits = array("lemon", "orange", "banana", "apple");
arsort($fruits);

print_r($fruits);

?>

The output of the code above will be:

Array ( [1] => orange [0] => lemon [2] => banana [3] => apple ) 

 

Q.4(C) Write a script to fill the combo box from mysql database.

<?php
$cn=mysql_connect("localhost","root","");
mysql_select_db("test_db",$cn);
?>
<html>
<body>
        <select name="mycombo">
            <?php
            $query=mysql_query("select * from student");
            while($rs=mysql_fetch_object($query))
            {
            ?>
            <option><?php echo $rs->s_name;?></option>

        <?php
            }
            ?>
         </select>
</body>
</html>

Output:

php paper solutions, solved papers of php, php solved question paper, php paper solution of vnsgu, php paper solution of gujarat university, php paper solution of banglore university, php paper solution of pune university

OR

Q.4(B). Write a script for login page with validations.

<?php
$cn=mysql_connect("localhost","root","");
mysql_select_db("test_db",$cn);
?>
<html>
<body>
<h1 align="center">My Login Page</h1>
<hr size="3"  color="#FF0000"/>

      <script language="javascript">
    function checkfrm()
    {
        if(document.frmlogin.txtlogin.value == "")
        {
            alert("Please Enter User Name..");
            document.frmlogin.txtlogin.focus();
            return false;
        }
        if(document.frmlogin.txtpassword.value == "")
        {
            alert("Please Enter Password..");
            document.frmlogin.txtpassword.focus();
            return false;
        }

    return true;
    }
    </script>
    <?php
      if(isset($_POST['submit']))
      {
            $sql = "select * from login where username='".$_POST['txtlogin']."' and password='".$_POST['txtpassword']."'";
            $rs = mysql_query($sql);
            if(mysql_num_rows($rs) > 0)
            {
                  header("location:welcome.php");
            }
            else
            {
                  echo "Invalid Login";
            }
      }
      ?>
    <form name="frmlogin" method="post" onsubmit="return checkfrm()">
            <table align="center">
                  <tr>
                        <td>User Name:</td>
                        <td><input type="text" name="txtlogin" /></td>
                  </tr>
                  <tr>
                        <td>Password:</td>
                        <td><input type="password" name="txtpassword"  /></td>
                  </tr>
                  <tr>
                  <td></td>
                        <td align="center">
                <input type="submit" name="submit" value="Login" />
                <input type="reset" /></td>
                  </tr>
            </table>
      </form>
</body>
</html>

Output:

LoginPage | php paper solutions, solved papers of php, php solved question paper, php paper solution of vnsgu, php paper solution of gujarat university, php paper solution of banglore university, php paper solution of pune university

 

Q5. Answer the following

 a)   Cookie

  • A cookie is a small text file that is sent by a web server to a web browser (client computer) and from the browser back again to the server whenever the server requests it.
  • It is state management technique to store small amount of data into text file to the client computer.
  • Cookies do not require any server resources since they are stored on the client
  • Cookies are used for many purposes including authenticating logged-in users, tracking shopping cart contents, maintaining user site preferences and more.
  • When you make a request for a website, it can save some data into text file and stored it to your computer or browser. so whenever you again request for the website , it reads cookie file and do further process.
  • Cookies are stores at client side so any person can view data by opening that text file so it unsecure technique to manage a state but it decreases sever load.
  • Two Types : 1)Persistence(have a life) 2)non persistence(does not have a life)

 

1.   Persistence: A persistent cookie is saved as a text file in client computer. Cookies enable you to store information about a client, session, or application. When a browser request a page, it sends the information in the cookie along with the request information.

 

2.   Non-persistence: it is temporary cookie, it holds a value until you close
your browser ,here cookie will automatically delete
when you close your browser.

 Advantage:

  • Cookies do not require any server resources because it stored on the client computer.
  • It remembers you so when you come back to same website there is no need to login it reads login information from your cookie file.

disadvantage:

  • You can store limited data to cookie(you can store up to 4kb data into cookie file, and only 20 cookies are allowed for per website)
  • Users can delete a cookies.
  • It is Not Secure because any person can view cookie file.
  • If  cookie will disable from the browser, cookie will not work.

setcookie()

setcookie() function is used to set a cookie

Syntax:

setcookie(name,value,expire);

Here is the detail of all the arguments:

  • Name – indicates cookie variable name.
  • Value – indicates value of cookie variable
  • Expiry – indicates expiry time of cookie file

Example:

<?php
   setcookie("test", "abc", time()+3600); //persistence cookie(for 1 hour)
   setcookie("name", "xyz"); //temporary(non-persistence) cookie
?>

How to Retrieve  a Cookie Value?

<?php
setcookie("test", "abc", time()+3600); //persistence cookie(for 1 hour)
setcookie("name", "xyz"); //temporary(non-persistence) cookie
echo $_COOKIE["test"];
echo $_COOKIE["name"];
print_r($_COOKIE); // prints all cookies in array
?>

 

How to Delete a Cookie?

Deleting a cookie is quite simple to do because all you have to do is to set the expiry time in the past. By doing this, the cookie will be automatically deleted as soon as it is created.

<?php
setcookie("test", "abc", time()+3600); //persistence cookie(for 1 hour)
setcookie("test", "", time()-3600); // it will delete a test cookie from your computer.
?>

 

Q.5(B)Conditional Structures in PHP

Conditional statements are used to perform different actions based on different conditions.

If…Else

  • This is used for either/or decisions. If the Boolean is true, the first block of code is executed. If the Boolean is false, the second code block is executed.

Syntax:

if (expr)

{

//Statements

}

else

{

//Statements

}

Example:

<?php
$a=10,$b=25;

            if ($a > $b)

{
         echo "a is greater than b";
}

else 

{
          echo "a is NOT greater than b";
}

?>

<?php
if ($a > $b)

{
    echo "a is bigger than b";
}

 elseif ($a == $b) 

{
    echo "a is equal to b";
}

else

{
    echo "a is smaller than b";
}
?>

 

Switch

  • The switch statement is similar to a series of IF statements on the same expression. In many occasions, you may want to compare the same variable (or expression) with many different values, and execute a different piece of code depending on which value it equals to. This is exactly what the switch statement is for.

Syntax:

switch(variable)

{

case case1:

//statements

break;

case case2:

//statements

break;

default:

//statements

break;

}

Example:

<?php

$i=”bar”;
switch ($i)

{
    case "apple":
        echo "i is apple";
        break;
    case "bar":
        echo "i is bar";
        break;
    case "cake":
        echo "i is cake";
        break;
}
?>

<?php
switch ($i)

{
    case 0:
        echo "i equals 0";
    case 1:
        echo "i equals 1";
    case 2:
        echo "i equals 2";
}
?>

<?php
switch ($i)

{
    case 0:
        echo "i equals 0";
        break;
    case 1:
        echo "i equals 1";
        break;
    case 2:
        echo "i equals 2";
        break;
    default:
       echo "i is not equal to 0, 1 or 2";
}
?>

? Operator:

  • An essential part of programming is evaluating conditions using if/else and switch/case statements. If / Else statements are easy to code and global to all languages. If / Else statements are great but they can be too long.
  • Ternary operator logic is the process of using “(condition) ? (true return value): (false return value)” statements to shorten your if/else structures.

Syntax:

truth_expr ? expr1 : expr2

Example:

<?php

echo $a<$b ? $a : $b;

?>

 

 

Q.5(C) PHP.ini

 

PHP.ini is very useful and it is a configuration file that is used to customize behavior of PHP at runtime. This enables easy administration in the way you administer Apache web server using configuration files. The Settings in which  upload directory, register global variables, display errors, log errors, max uploading size setting, maximum time to execute a script and other configurations is written in this file.

 

When PHP Server starts up it looks for PHP.ini file first to load various values for settings. If you made changes in PHP.ini then you need to restart your server to check the changes be effected. Default php.ini file of web server. the copy of this ini file can be found in /usr/local/lib/php/ for UNIX installation.

 

If you want to do some custom configurations then you can also write your own php.ini file. For this copy php.ini template file, make necessary changes in values directives according to your need rename it to php.ini then copy it to desired location in root of your web directory or in any particular folder. But hosting should allow for running this file. The PHP runtime will take values only for settings which are specified in php.ini file if you are using your own, for rest of settings it will take defaults of PHP runtime. So if you are writing your own php.ini, keep in mind to overwrite every settings specified in web server’s php.ini file this cannot be used as an extension of web server’s php.ini file.

 

 The php.ini file is a special file for PHP.

 

The php.ini file is where you declare changes to your PHP settings. You can use the default settings for the server, change specific settings by editing the existing php.ini, or create a new text file and name it php.ini.

Download Paper Solutions from Below Link

About admin

Scroll To Top