Showing posts with label Basic PHP Programs. Show all posts
Showing posts with label Basic PHP Programs. Show all posts

Wednesday, August 8, 2018

phpMyPassion

PHP Program To Find Odd Even Number

Find Odd Even Number || PHPMYPASSION

"Find odd even number " is the basic PHP program for a PHP learner. As you all aware, Odd numbers are not divisible by 2 and Even numbers are divisible by 2. 

Example :
    Odd number: 3, 5, 7, 9,11
    Even number: 2, 4, 6, 8, 10 

So here I am gonna explain it with a simple PHP program.

Odd Even Number Program :-


<?php

$number=22;

if($number%2==0)
{
 echo "22 is an even number"; 
}
else
{
 echo "22 is not odd number";
} 

?>

Output :-

22 is an even number


You can also do this by defining a PHP function to check a number is odd or even as below -



PHP function to check odd even number :-


<?php
function checkOddEven($num)
{
   if($num%2==0)
   {
     $result = "Even number"; 
   }
   else
   {
     $result = "Odd number";
   }
   retrun $result;
}

echo checkOddEven(43);
?>

Output :-

Odd number
Read More

Tuesday, August 7, 2018

phpMyPassion

Swap Two Number Program In PHP

Swap Two Numbers Program || PhpMyPassion

Swap two number generally is the process of interchange two variables with each other. Just suppose you have X whose value 10 there is another number Y with value of 20. Now if we swap these two number with each other then the X value will change to 20 and Y  value will change to 10.

So here I am gonna explain with a simple PHP program.

Swap Two Number Program :-


<?php

$x=10;
$y=20;

echo "Value of x: $x</br>";
echo "Value of y: $y</br>";

$temp=$x;
$x=$y;
$y=$temp;

echo "Value of x: $x</br>";
echo "Value of y: $y</br>";

?>

Output :-

Value of x: 10
Value of y: 20
Value of x: 20
Value of y: 10


You can also do this by without using third variable as below -

Swap Two Number Without Using Third Variable Program :-


<?php

$x=10;
$y=20;

echo "Value of x: $x</br>";
echo "Value of y: $y</br>";

$x=$x+$y;
$y=$x-$y;
$x=$x-$y;

echo "Value of x: $x</br>";
echo "Value of y: $y</br>";

?>

Output :-

Value of x: 10
Value of y: 20
Value of x: 20
Value of y: 10

Read More

Saturday, January 20, 2018

phpMyPassion

Adding Two Numbers in PHP


We can add two numbers in PHP as like other programming language. "Two Numbers Addition" is the initial program from where most of the beginner developers will start to learn and write code in any language. Here is an example of add two numbers in PHP.

Adding Two Numbers Program :-

We use $ symbol to declare variable and add two variables. we take third number to store result in third variable. Below is the simple PHP program to add two numbers.

<?php

$first=30;
$second=20;
$third=$first + $second;

echo "Two Numbers Sum: ".$third;

?>

Output :-

Two Numbers Sum: 50
Read More

Thursday, December 28, 2017

anil

How to Print Hello World Program in PHP ?

In PHP it is very easy to print "Hello World" program. "Hello World." is the first program from where most of the beginner developers will start to write code in any language. Here is an example of how to print "Hello World!!" in PHP.


Print "Hello World" Program :-

In PHP we use echo to print a string and we always write the PHP code between <?php ?>  tag. Below are the example of print simple Hello World.

<?php

echo "Hello World!!";

?>

Output :-

Hello World!!

Check video :-


Read More
phpMyPassion

PHP Introduction

What is PHP:-

PHP stands for PHP: Hypertext Preprocessor , it is widely - used server side scripting  language designed for web devlopment. PHP also used as a general purpose programming language. It was build up by Rasmus Lerdorf in 1994 and launched in the market in 1995.

PHP is the most well known scripting language on the web. It is utilized to improve site pages. Using PHP, you can do things like a login page and login a user by creating session, check details from a form, create forums, picture galleries, surveys, and a whole lot more.

PHP scripts are executed on the server like - xampp, wamp etc. 

What You Should Already Know :-

Before you learn PHP you should have a basic understanding of the following things:
  • HTML
  • CSS
  • JavaScript
  • OOPs Concepts

What You Will Learn Here:-

Here we mainly focus on basic PHP program as below-
  • prime number program
  • odd even code
  • factorial program
  • print table in php
  • print star patter in php
  • print number pattern in php
  • PHP - Armstrong number
  • PHP - Palindrome number
  • PHP - Prime Number Program
  • PHP - Fibonacci Series
  • PHP - Reverse number in PHP
  • PHP - Reverse Sting in PHP
Read More