Practical program exercise 6 PHP Basic Programing for 12th computer applications
PHP Basic Programing
Ternary operator
- Ternary operator is also known as conditional operator that evaluate something based on a condition being true or false.
- It simply allows testing a condition in a single line replacing the multiline if-else making the code compact.
Functions:
- A function is that they are reusable; if you have a task that needs to be performed a number of times, a function is an ideal solution.
SYNTAX:
function functionName()
{
Custom Logic code to be executed;
}
- A user-defined Function declaration begins with the keyword “function”. User can write any custom logic inside the function block.
Concatenation
- Two operators are used to perform string related operations such as Concatenation
- $text1 . $ text2
Basic Rules for Variable Declaration
- Variable name must always begin with a $ symbol.
- Variable name can never start with a number.
- Variable names are case-sensitive.
Embed PHP in HTML
- PHP script can be written in side the HTML code and save the file with extension of .php.
- The embedded PHP file get executed in the Webserver, the browser receives only the HTML and other client side files.
PHP
- PHP is one of the most widely used and recognizable technologies in use on the internet.
- Originally PHP stood for “Personal Home Page”, though more recently it has been changed to stand for “PHP: Hypertext Preprocessor”.
CA – 6 PHP – BASIC PROGRAMING
QUESTION:
Write a PHP code to display the given number is either greater than 30 or 20 or 10 using function with ternary operator.
AIM:
To create and execute a basic PHP programming
PROCEDURE:
- Start Xampp server (Apache)
- Go to virtual path folder (C:\xampp\htdocs)
- Create test.php file and type the program
- Execute the program on your Web browser using by this URL link (http://localhost/test.php)
PROGRAM:
<html>
<body>
<?php
echo “Welcome to Our School <br>”;
$color = “blue”;
echo “My car is $color <br>”;
echo “My dress is $COLOR <br>”;
echo “My box is $coLOR <br>”;
function trinary_Test($n)
{
$r = $n > 30
? “greater than 30<br>”
: ($n > 20
? “greater than 20<br>”
: ($n >10
? “greater than 10<br>”
: “Input a number atleast greater than 10!<br>”));
echo $n.” : “.$r.”\n”;
}
trinary_Test(32);
trinary_Test(21);
trinary_Test(12);
trinary_Test(4);
?>
</body>
</html>
OUTPUT:
Welcome to Our School
My car is blue
32 : greater than 30
21 : greater than 20
12 : greater than 10
4 : Input a number atleast greater than 10!
RESULT:
The Output was verified successfully