Professional Documents
Culture Documents
<?php
function simple ()
{
echo "In simple ()<br />\n";
}
function data ($arg = '')
{
echo "In data (); argument was '$arg'.<br />\n";
}
$func = 'simple';
$func(); // This calls simple()
$func = 'data';
$func('test'); // This calls data ()
?>
OUTPUT:
In simple ()
In data (); argument was 'test'.
4 marks:
1. Difference between array_pop () and array_push () (with example)
array_pop() array_push()
The array_pop() method is used to pop the The array_push() method is used to push
elements from the array. multiple elements in the array
simultaneously
.
The elements are removed from the end Elements are inserted in the order in
one by one each time when this method is which they are specified in the method call
called.
Syntax: Syntax:
array_pop($array) array_push($array, $ele1, $ele2, ...)
It takes array as an argument It takes multiple array elements as
argument
Example: Example:
<?php $arr = array();
array_push($arr, 1, 2, 3, 4, 5); array_push($arr, 1, 2, 3, 4, 5);
print_r("Array after multiple insertions print_r("Array after multiple insertions
</br>"); </br>");
print_r($arr); print_r($arr);
array_pop($arr);
print_r("Array after a single pop </br>");
print_r($arr);
<?php
$num = array (40, 61, 2, 22, 13);
echo "Before Sorting:<br>";
foreach ($num as $key=>$value) {
echo $value. "<br>";
}
sort($num);
echo "After Sorting in Ascending order:<br>";
foreach ($num as $key=>$value) {
echo $value. "<br>";
}
echo "After Sorting in Descending order:<br>";
rsort($num);
foreach ($num as $key=>$value) {
echo $value. "<br>";
}
?>
OUTPUT:
Before Sorting: 40 61 2 22 13
After Sorting in Ascending order: 2 13 22 40 61
After Sorting in Descending order: 61 40 22 13 2
8. Write a PHP code to read and display user information as Name, Email, ContactNo using
multi-dimensional array.
<?php
// Defining a multidimensional array
$person = array(
array(
"name" => "Yogita K",
"mob" => "5689741523",
"email" => "yogi_k@gmail.com",
),
array(
"name" => "Manisha P.",
"mob" => "2584369721",
"email" => "manisha_p@gmail.com",
),
array(
"name" => "Vijay Patil",
"mob" => "9875147536",
"email" => "Vijay_p@gmail.com",
)
);
// Accessing elements
echo "manisha P's email-id is: " . $person[1]["email"], "<br>";
echo "Vijay Patil's mobile no: " . $person[2]["mob"];
?>
Output:
Manisha P's email-id is: manisha_p@gmail.com
Vijay Patil's mobile no: 9875147536
6 marks:
1. WAP to create PDF document.
<?php
require('fpdf/fpdf.php');
class PDF extends FPDF
{
// Page header
function Header()
{
// Set font family to Arial bold
$this->SetFont('Arial', 'B', 20);
// Move to the right
$this->Cell(80);
// Header
$this->Cell(50, 10, 'Heading', 1, 0, 'C');
// Line break
$this->Ln(20);
}
// Page footer
function Footer()
{
// Position at 1.5 cm from bottom
$this->SetY(-15);
// Arial italic 8
$this->SetFont('Arial', 'I', 8);
// Page number
$this->Cell(0, 10, 'Page ' . $this->PageNo() . '/{nb}', 0, 0,
'C');
}
}
// Instantiation of FPDF class
$pdf = new PDF();
// Define alias for number of pages
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetFont('Times', '', 14);
for ($i = 1; $i <= 30; $i++)
$pdf->Cell(0, 10, 'line number ' . $i, 0, 1);
$pdf->Output();
?>