ad

Thursday, April 11, 2024

php Array

 PHP Array 

PHP Array


1] PHP Array is variable can store only one values

2] And array is use to store multiple value of a same data type.

3] To create an array we used [ ] square bracket.

4] By Default first element in and array store at Index No "0".

5] To access value in an array pass index No in square bracket.


 PHP ARRAY TYPES :-

1] Indexed  Array 

2] Associative Array

 3] Multidimension Array

PHP Array

Example :-

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title> array </title>
</head>
<body>
    <?php
       $student= array("vitthal","seeta", "ram","shyam","radha","rukmini","krishna");

       var_dump($student);
    ?>
   
</body>
</html>

PHP Array

Output :-

PHP Array  output

PHP Array

Example :-

Q calculate length of array that is number array element.


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>array</title>
</head>
<body>
    <?php
      $student=["vitthal","radha","seeta","ram"];
      $length=count($student);
      echo "No of array element=".$length;
 
    ?>
</body>
</html>


PHP Array

Output :-

No of array element=4

Related Post :-


php data and time function

about us page design template

php program print diamond number pattern

Wednesday, April 10, 2024

PHP for loop

 PHP for loop

PHP for loop


Information :-

1]  The loop is the most complex loop in PHP and is used when the user knows             how often the block should be executed.

 2]  A for loop consists of an initialization statement, a test statement, and an     update statement (an increment or decrement statement).

3]  Loops
 for PHP can be used to iterate over a series of scheduled code.

4] If
 the number of iterations is known you should use it, otherwise use a loop.

5]  This means that you will use a loop when you already know how many     times you want to run a piece of code.


Syntax :-

for (initialization; condition; increment/decrement)

{

// enter code and executed 

syntax  explanation :-

  • initialization :-
  • This part is executed once before the loop starts. It often used to initialize variables.

  • condition:-
  • The condition that is evaluated before each iteration of the loop. If the condition evaluates to true, the loop continues; If it evaluates to false, the loop ends.

  • increment/decrement :- This is done after each iteration of the loop. It is usually used to increase or decrease a number.


 Flowchart     

PHP FOR loop /output


 PHP for loop

Example :-

Q 1. show all number 20 to 50.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
<?php
for ($no=20;$no<50;$no++)
{
   echo $no.", ";
}
?>

</body>
</html>

 PHP for loop

Output :-


PHP  for loop output

Q.2 Show all number Between 100 to 50 descending order.

 PHP for loop

Example :-

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
<?php
for($no=100; $no>50;$no--)
{
   echo$no.", ";
}
?>

</body>
</html>


 PHP for loop

Output :-

PHP program no descending order output


Related Post :-

javascript bitwise operators


php program tp print alphabet pattern C

Tuesday, April 9, 2024

PHP While loop

 

PHP While loop

PHP While loop


 Information :-

1] PHP while loop can be used to return from the same process as the loop.

2] The while loop repeats a block of code until the condition is FALSE. 

3] Exit the body loop when the condition is FALSE.

4]
This
 loop should be used if the number of iterations is unknown.

5] Element
 loop is also called Entry check loop because 
the condition is checked          before entering the loop body. 

6] This means diagnosing the condition first. If the condition is true,           the code block is executed.


Syntax :-



Flowchart :-

PHP while loop /output




PHP While Loop 

Example :-

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
<?php
/*decending order in php*/
 $no =10;
 while ($no>0)
 {
    echo $no."<br>";
    $no --;
 }

 /**10,9,8,7,6,5,4,3,2,1 */
 
 
 
?>

</body>
</html>


PHP While Loop 

OUTPUT :-