Home
PHP Examples
Showing posts with label PHP Examples. Show all posts
Showing posts with label PHP Examples. Show all posts
PHP Program how to use the print
PHP program to explain the use of echo
php source-:
<!DOCTYPE html>
<html>
<body>
<?php
echo "<h2>PHP is Fun!</h2>";
echo "Hello world!<br>";
echo "I'm about to learn PHP!<br>";
echo "This ", "string ", "was ", "made ", "with multiple parameters.";
?>
</body>
</html>
output-:
PHP is Fun!
Hello world!I'm about to learn PHP!
This string was made with multiple parameters.
PHP Program how to use static variable example
PHP program how to use $GLOBALS[] array example
PHP Program how to use global keyword to access global variable
PHP Local scope of a variable ( variable inside a function )
php source
<!DOCTYPE html>
<html>
<body>
<?php
function myTest() {
$x = 5; // local scope
echo "<p>Variable x inside function is: $x</p>";
}
myTest();
// using x outside the function will generate an error
echo "<p>Variable x outside function is: $x</p>";
?>
</body>
</html>
Output
Variable x inside function is: 5
Variable x outside function is:
PHP globle scope of variable example program ( variable outside a function )
php source
<!DOCTYPE html>
<html>
<body>
<?php
$x = 5; // global scope
function myTest() {
// using x inside this function will generate an error
echo "<p>Variable x inside function is: $x</p>";
}
myTest();
echo "<p>Variable x outside function is: $x</p>";
?>
</body>
</html>
Output
Variable x inside function is:
Variable x outside function is: 5
PHP Types of variables
PHP Variable are not case sensitive
PHP Functions, Keywords are not case-sensitive
How to use comment in PHP
Comment_example.php
<!DOCTYPE html>
<html>
<body>
<?php
// This is a single-line comment
# This is also a single-line comment
/*
This is a multiple-lines comment block
that spans over multiple
lines
*/
// You can also use comments to leave out parts of a code line
$x = 5 /* + 15 */ + 5;
echo $x;
?>
</body>
</html>
Result
10
PHP Program to write a simple string
Subscribe to:
Posts
(
Atom
)
