Featured Post Today
print this page
Latest Post

Learn Simple While Loop in PHP

Now you can learn while loop very easily. Just you need to read code and understand the comments. try this code and implement on PHP Editor.


 <?php  
           $num=0; //1st we need to asign a value to varible   
                          while ($num <= 10) // Here we need to apply condition  
                          {  
                               echo "{$num}" . <br />; // here we need to show results  
                               $num++; // here we need to add increament.   
                          }  
 ?>  
0 comments

Get current month function with if else if statement

Try this code, you can learn that how to get current day, month, year in PHP. PHP will get complete data from your system setting and will print out. 


 <?php  
           $date = date("d M y"); //It is used to get current month , date , year  
                          echo $date . "<br />";  
           if ($date == "Sep")  
           {  
           echo "It is september";  
           }  
           else  
           {  
           echo "It is Octobar";  
           }  
                          ?>  
0 comments

Switch Statement in PHP

php switch statement

Switch statement is conditional statement. It is used same as if else if statement. It is used to find the best condition. Its simple code is given bellow


 <?php  
                          $name="Feroz"; //Need to asign a value to variable  
                switch ($name) //need to add variable which needs to optimise for condition  
                               {  
                                    case "Sami":   
                                    echo "I am Sami";  
                                    break;  
                                    case "ullah":  
                                    echo "I am Samee Ullah";  
                                    break;  
                                    case "sheikh":  
                                    echo "I am Sheikh";  
                                    break;  
                                    case "Feroz":  
                                    echo "I am Samee Ullah Feroz";  
                                    break;  
                                    default:  
                                    echo "I m Samee Ullah Feroz cast sheikh";  
                               }  
                          ?>  

Updated 22 Oct, 2013:
Some times, we forget to add break after completion of any case. It can create bug in your output. Because in this situation, code will execute other cases and also will show their outputs.
0 comments

PHP Array Important Functions : 8th Day Lecture of PHP

array functions in php

PHP Array Important Functions

PHP array_fill Function and its usage

Array ( [3] => Sheikh Ansari [4] => Sheikh Ansari [5] => Sheikh Ansari [6] => Sheikh Ansari )

PHP array_pop Function and its usage

Sheikh

PHP array_push Function and its usage

Array ( [0] => Samee [1] => ullah [2] => Feroz [3] => Sheikh )

PHP array_reverse Function and its usage

Array ( [0] => Sheikh [1] => Feroz [2] => Ullah [3] => Samee )

PHP array_search Function and its usage

2

PHP array_slice Function and its usage

Array ( [0] => Feroz [1] => Sheikh [2] => Ansari )
Array ( [0] => Feroz [1] => Sheikh )

PHP array_unique Function and its usage

Array ( [0] => Samee [1] => Ullah [2] => 3 [3] => Sheikh )

PHP count Function and its usage

5

PHP current Function and its usage

Samee

PHP next Function and its usage

Ullah
Feroz

PHP reset Function and its usage

Samee
Feroz
Samee

PHP shuffle Function and its usage

Array ( [0] => Sheikh [1] => Ansari [2] => Samee [3] => Feroz [4] => Ullah )

 <html>  
   <head>  
     <title><?php $pagetitle="PHP Array Important Functions ";  
                               define("blogname","Samee Articles");  
                          echo $pagetitle . ":" . blogname ?></title>  
         <meta name="description" content="<?php echo $pagetitle ?>" />  
         <meta name="robots" value="nofollow, noindex" />  
     <link rel="icon" type="image/ico" href="http://www.iconarchive.com/download/i50954/deleket/3d-cartoon-vol3/Web-Coding.ico" alt="Icon" />  
     <link type="text/css" href="stylesheet.css" rel="stylesheet" />  
   </head>  
   <body>  
        <div id="main">  
       <img id="logo" src="http://icons.iconarchive.com/icons/deleket/3d-cartoon-vol3/256/Web-Coding-icon.png" alt="Coding">  
           <?php  
                               function b()  
                               {  
                               echo "<br />";  
                               }  
                          ?>  
       <h1 align="center"><?php echo $pagetitle ?></h1>  
          <h2 align="left">PHP array_fill Function and its usage</h2>  
                          <?php  
                $emp = array();  
                               $emp=array_fill(3,4,"Sheikh Ansari"); //it is used to fill the array ; 3rd value and remaining 4 values  
                               print_r($emp);  
                               b();  
                          ?>  
         <h2 align="left">PHP array_pop Function and its usage</h2>  
           <?php  
             $str = array("Samee","ullah","Sheikh");  
                               echo array_pop($str); //it is used delete the last element of the error and show it.  
                               b();  
                          ?>  
         <h2 align="left">PHP array_push Function and its usage</h2>  
           <?php  
             $str = array("Samee","ullah","Feroz");  
                               array_push($str,"Sheikh"); //it is used return the last value end of the array  
                               print_r($str);  
                               b();  
                          ?>  
         <h2 align="left">PHP array_reverse Function and its usage</h2>  
           <?php  
             $str = array("Samee","Ullah","Feroz", "Sheikh");  
                               $name = array_reverse($str); //1st you need to asign complete array to an other variable; then you need to print out that array  
                               print_r($name);  
                               b();  
                          ?>  
         <h2 align="left">PHP array_search Function and its usage</h2>  
           <?php  
             $str = array("Samee","Ullah","Feroz", "Sheikh");  
                               echo array_search("Feroz",$str); //It is used to find th element in array.  
                               b();  
                          ?>  
          <h2 align="left">PHP array_slice Function and its usage</h2>  
           <?php  
             $str = array("Samee","Ullah","Feroz", "Sheikh", "Ansari");  
                               print_r (array_slice($str, 2)); //It is used to make a slice from 2nd value to end  
                               b();  
                               $str = array("Samee","Ullah","Feroz", "Sheikh");  
                               print_r (array_slice($str, 2, 3)); //It is used to make a slice from 2nd value to 3rd value  
                               b();  
                          ?>  
         <h2 align="left">PHP array_unique Function and its usage</h2>  
           <?php  
             $str = array("Samee","Ullah",3, "Sheikh", "Samee");  
                               print_r (array_unique($str)); //It is used to remove duplicate value in the array  
                               b();  
                          ?>  
         <h2 align="left">PHP count Function and its usage</h2>  
           <?php  
             $str = array("Samee","Ullah",3, "Sheikh", "Samee");  
                               print_r (count($str)); //It is used to count the values in array  
                               b();  
                          ?>  
         <h2 align="left">PHP current Function and its usage</h2>  
           <?php  
             $str = array("Samee","Ullah",3, "Sheikh", "Samee");  
                               print_r (current($str)); //It is used to print 1st value of the array  
                               b();  
                          ?>  
         <h2 align="left">PHP next Function and its usage</h2>  
           <?php  
             $str = array("Samee","Ullah","Feroz", "Sheikh", "Ansari");  
                               print_r (next($str)); //It is used to print (2nd value) next to 1st value of the array  
                               b();  
                               print_r (next($str)); //It is used to print (3rd value) next to next to 1st value of the array  
                               b();  
                          ?>  
         <h2 align="left">PHP reset Function and its usage</h2>  
           <?php  
                               $array = array('Samee', 'Ullah', 'Feroz', 'Ansari');  
                               echo current($array) . "<br />\n"; //1st element  
                               next($array);  
                               next($array); // skip two steps  
                               echo current($array) . "<br />\n";  
                               reset($array); //reset is used to reset the array elements.   
                               echo current($array) . "<br />\n";   
                               b();  
                          ?>  
         <h2 align="left">PHP shuffle Function and its usage</h2>  
           <?php  
             $str = array("Samee","Ullah","Feroz", "Sheikh", "Ansari");  
                               shuffle($str); //It will shuffle array elements on every refresh  
                               print_r ($str);  
                          ?>   
   </body>  
 </html>  



0 comments

PHP Conditional Statements : If Else If Statements : 7th Day Lecture of PHP



PHP Conditional Statements : If Else If Statements

What is PHP Conditional Statements?

when you write code, you want to perform different actions for different decisions.
You can use conditional statements in your code to do this
  1. If : executes some code only if a specified condition is true
  2. if...else statement - executes some code if a condition is true and another code if the condition is false
  3. if...elseif....else statement - selects one of several blocks of code to be executed

If Example

if...else Example

Have a good night!

if...elseif....else else Example

Have a good night!

 <html>  
   <head>  
     <title><?php $pagetitle="PHP Conditional Statements : If Else If Statements";  
                               define("blogname","Samee Articles");  
                          echo $pagetitle . ":" . blogname ?></title>  
         <meta name="description" content="<?php echo $pagetitle ?>" />  
         <meta name="robots" value="nofollow, noindex" />  
     <link rel="icon" type="image/ico" href="http://www.iconarchive.com/download/i50954/deleket/3d-cartoon-vol3/Web-Coding.ico" alt="Icon" />  
     <link type="text/css" href="stylesheet.css" rel="stylesheet" />  
   </head>  
   <body>  
        <div id="main">  
       <img id="logo" src="http://icons.iconarchive.com/icons/deleket/3d-cartoon-vol3/256/Web-Coding-icon.png" alt="Coding">  
       <h1 align="center"><?php echo $pagetitle ?></h1>  
          <h2 align="left">What is PHP Conditional Statements?</h2>  
           <?php  
             echo "when you write code, you want to perform different actions for different decisions.<br>  
                               You can use conditional statements in your code to do this";  
                               echo "<ol type=\"A\">  
                                         <li>If : executes some code only if a specified condition is true</li>  
                                         <li>if...else statement - executes some code if a condition is true and another code if the condition is false</li>  
                                         <li>if...elseif....else statement - selects one of several blocks of code to be executed</li>  
                                         </ol>";  
           ?>   
          <h2 align="left">If Example</h2>  
           <?php  
                               $t=date("H");  
                               if ($t<"20")  
                                {  
                                echo "Have a good day!";  
                                }  
           ?>   
          <h2 align="left">if...else Example</h2>  
           <?php  
                               $t=date("H");  
                               if ($t<"20")  
                                {  
                                echo "Have a good day!";  
                                }  
                               else  
                                {  
                                echo "Have a good night!";  
                                }  
                          ?>  
         <h2 align="left">if...elseif....else else Example</h2>  
           <?php  
                               $t=date("H");  
                               if ($t<"10")  
                                {  
                                echo "Have a good morning!";  
                                }  
                               elseif ($t<"20")  
                                {  
                                echo "Have a good day!";  
                                }  
                               else  
                                {  
                                echo "Have a good night!";  
                                }  
                          ?>  
     <div id="sidebar">  
       <ul>  
            <li><?php echo "<a href=\"http://sameearticles.blogspot.com\">blogname</a>"?></li>  
         <li><a href="http://www.blogger.com/home">Blogger</a></li>  
         <li><a href="http://sameearticles.blogspot.com/search/label/PHP%20Learning">PHP Learning</a></li>  
         <li><a href="http://seoacquire.blogspot.com">SEO Knowledge</a></li>  
         <li>CSS Learning</li>  
       </ul>  
           </div>    
   </body>  
 </html>  


0 comments

Array Types in PHP : 7th Day Lecture of PHP


php arrays

Types of Array In PHP : Samee Articles

Sample 1 : Types of Array in PHP.

Types of Array In PHP
  1. Indexed arrays - Arrays with numeric index
  2. Associative arrays - Arrays with named keys
  3. Multidimensional arrays - Arrays containing one or more arrays

Sample 2 : Indexed Arrays Example And Use in PHP.

My 1st name is Samee.
My Last Name is Feroz
My Cast is Sheikh.
array (size=4)
  0 => string 'Samee' (length=5)
  1 => string 'Ullah' (length=5)
  2 => string 'Feroz' (length=5)
  3 => string 'Sheikh' (length=6)
Values in Array = 4

Sample 3 : Associative arrays Example And Use in PHP.

My 1st name is Samee .
My Last Name is Feroz
My Cast is Sheikh.
array (size=4)
  'firstname' => string 'Samee' (length=5)
  'middlename' => string 'Ullah' (length=5)
  'lastname' => string 'Feroz' (length=5)
  'cast' => string 'Sheikh' (length=6)

Sample 4 : Multidimensional arrays arrays Example And Use in PHP.

array (size=2)
  0 => 
    array (size=4)
      0 => string 'Samee' (length=5)
      1 => string 'Ullah' (length=5)
      2 => 
        array (size=1)
          0 => string 'Sheikh' (length=6)
      'cast' => string 'Sheikh' (length=6)
  1 => string 'Feroz' (length=5)
My 1st name last part is Ullah

 <html>  
   <head>  
     <title><?php $pagetitle="Types of Array In PHP : 6th Day Lecture : Samee";  
                          echo $pagetitle; ?></title>  
         <meta name="description" content="<?php echo $pagetitle ?>" />  
         <meta name="robots" value="nofollow, noindex" />  
     <link rel="icon" type="image/ico" href="http://www.iconarchive.com/download/i50954/deleket/3d-cartoon-vol3/Web-Coding.ico" alt="Icon" />  
     <link type="text/css" href="http://www.getacho.com/download/phpcss/stylesheet.css" rel="stylesheet" />  
   </head>  
   <body>  
        <img id="logo" src="http://icons.iconarchive.com/icons/deleket/3d-cartoon-vol3/256/Web-Coding-icon.png" alt="Coding">  
     <h1 align="center">Types of Array In PHP : <a href="http://sameearticles.blogspot.com" target="_blank">Samee Articles</a></h1>  
       <h2 align="left">Sample 1 : Types of Array in PHP.</h2>  
         <?php  
                          echo "Types of Array In PHP <br />";  
                          echo  
                          "<ol type=\"a\">  
                          <li>Indexed arrays - Arrays with numeric index</li>  
                          <li>Associative arrays - Arrays with named keys</li>  
                          <li>Multidimensional arrays - Arrays containing one or more arrays</li>  
                          </ol> <br />";  
         ?>  
       <h2 align="left">Sample 2 : Indexed Arrays Example And Use in PHP.</h2>  
         <?php  
                          $name = array("Samee", "Ullah", "Feroz"); //It is the way to add an index array  
                          $name[3]="Sheikh"; //It is the way to add a value to 3rd number of array, it is custom way  
                          echo "My 1st name is $name[0]. <br />";  
                          echo "My Last Name is " . $name[2] . "<br />";  
                          echo "My Cast is {$name[3]}. <br>";  
                          var_dump($name);  
                          echo "Values in Array = \t" . count($name); //this function is for counting the values of Array  
         ?>  
       <h2 align="left">Sample 3 : Associative arrays Example And Use in PHP.</h2>  
         <?php  
                          $name = array("firstname"=>"Samee","middlename"=>"Ullah","lastname"=>"Feroz"); #It is the way to add an assosiative array  
                          $name['cast'] = "Sheikh"; //you can use double or single qoutes both methods with in []  
                          echo "My 1st name is {$name["firstname"]} . <br />";  
                          echo "My Last Name is " . $name["lastname"] . "<br />";  
                          echo "My Cast is {$name["cast"]}. <br>";  
                          var_dump($name);  
         ?>  
       <h2 align="left">Sample 4 : Multidimensional arrays arrays Example And Use in PHP.</h2>  
         <?php  
                          $name= array(array("Samee","Ullah"),"Feroz"); //array within array is called multidimensional array  
                          /*$name[0][2][0]="Sheikh";*/ //1st way to write one integer between array  
                          $name[0]["cast"]="Sheikh"; //2nd way to write one integer between array  
                          var_dump($name);  
                          echo "My 1st name last part is ". $name[0][1]; //it is used to find the path  
         ?>  
   </body>  
 </html>  

0 comments
 
Copyright © 2011-2026. Samee Articles - All Rights Reserved
Proudly powered by Blogger