Monday, April 15, 2024

PHP Syntax


PHP Syntax

PHP Syntax


PHP Syntax:-

 1]  PHP is a server-side coding language widely used for web development. 

 2] PHP code is often embedded in HTML

 3] PHP files usually have save the ".php" extension.

 4] PHP file contains the HTML tags   some PHP code.

 5] PHP script that uses the built-in PHP function "echo" to display text

PHP's syntax is similar to the C language. PHP is a server-side coding language. PHP code is stored as a text file with the ".php" extension. A ".php" file is essentially a web page with HTML text interspersed between one or more blocks of PHP code. 

However, it must be opened in a browser with HTTP protocol URLs. In other words, if you double-click on the PHP file icon, it will open locally using the file protocol. For example, if you open the "index.php" file in the root folder of the Apache server, only the text of the PHP code will be displayed. However, if you start the Apache server and

 open the URL http://localhost/index.php, the Apache home page will be displayed. Therefore, a PHP parser needs to distinguish between PHP code and other content. When the ".php" file is opened on the website, the HTML engine performs the HTML/CSS/JavaScript part and runs on HTML blocks when it encounters the words contained in the PHP tags. The PHP parser process blocks the response and passes it back to the browser.


Syntax :-

<?php

//php code here


?>

PHP Syntax:-

Example :-

<!doctype html>
<html>
    <head>
        <title>html code and php code</title>
    </head>
<body>
    <h1>MY FIRST PROGRAM IN PHP </h1>
    <?php
    echo "Hello friends
     How are your
        fine "
         ?>
</body>
</html>


PHP Syntax 

Output :-

php syntax/output




Read more

php array type

php for loop

php switch statement

php string operators

php data type

Saturday, April 13, 2024

php array types

 

PHP ARRAY TYPES

PHP Array Type


PHP ARRAY

  1]Array is a special type of variable that we use to store        or store multiple values in a single variable without creating     multiple variables to store these values.

  2]  We
 use the array function ( ) to create an array in PHP.


PHP ARRAY TYPES :-

1] Indexed  Array 

 1]  PHP index array is an array represented by an index number. 
 2] All elements of an array are represented by index numbers starting from 0. 
 3] PHP index arrays can store numbers, strings, or single objects. 
 4] PHP indexed arrays are also called numeric arrays.

SYNTAX ::- 

   foreach($array as $value)
       {
            statement;
            statement;
            statement;
           }


PHP Array Type

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","radha","ram");
     rsort($student);
     foreach($student as $a)
     {
        echo $a."<br>";
     }
    ?>
</body>
</html>

PHP Array Type

Output

vitthal
seeta
ram
radha

2] Associative Array

 1] PHP allows you to associate a name/tag with any string in PHP using the => symbol.
 2] This way you can easily remember because each element is represented by a label instead of an additional number.

SYNTAX ::-

foreach ($array as $key => $value)
      {
            
         statement;
         statement;
      }

 Associative 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(3=>"vitthal",1=>"seeta",2=>"radha");
    foreach($student as $x=>$y)
    {

    echo $y."your Roll no is ".$x."<br> ";
   }
    ?>
</body>
</html>

 Associative Array

Output ::-

vitthalyour Roll no is 3
seetayour Roll no is 1
radhayour Roll no is 2

 3] Multidimension Array

1] PHP multidimensional arrays are also called arrays. 
2] It allows you to store table data in an array.
3] In PHP, multidimensional arrays can be represented as a row*column matrix.

 Multidimension 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
$COMPANY = array (
  array("TCS",22,18),
  array("IBM",15,13),
  array("INFOSYS",5,2),
  );
 
echo $COMPANY[0][0].": In stock: ".$COMPANY[0][1].", sold: ".$COMPANY[0][2].".<br>";
echo $COMPANY[1][0].": In stock: ".$COMPANY[1][1].", sold: ".$COMPANY[1][2].".<br>";
echo $COMPANY[2][0].": In stock: ".$COMPANY[2][1].", sold: ".$COMPANY[2][2].".<br>";

?>

</body>
</html>

      Multidimension Array::-

Output :-

TCS: In stock: 22, sold: 18.
IBM: In stock: 15, sold: 13.
INFOSYS: In stock: 5, sold: 2.



READ MORE 






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

READ MORE


PHP else if ladder

PHP if Statements

PHP increment/ decrement operators