Posts

Multidimensional array in PHP

  Multidimensional array: Multidimensional allows us to create more than one array within an array; it is a nested array, meaning the nesting of array definitions within one another. Multidimensional indexed array: Example 1: Create an array with square brackets and array(). <?php $a=[ ]; // array (); We can also use an array function here. $a[0][0]=1; $a[0][1]=12; $a[0][2]=13; $a[1][0]=14; $a[1][1]=15; $a[1][2]=16; $a[2][0]=17; $a[2][1]=18; $a[2][2]=19; echo $a[0][0],"\t"; echo $a[0][1],"\t"; echo $a[0][2],"\t\n"; echo $a[1][0],"\t"; echo $a[1][1],"\t"; echo $a[1][2],"\t\n"; echo $a[2][0],"\t"; echo $a[2][1],"\t"; echo $a[2][2],"\t"; ?> OUTPUT 1        12       13 14       15       16 17       18       19 Example 2: <?php $a=[[1,2,3],[4,5,6],[7,8,9]]; // arra...

Conditional statements: if, if-else, switch, The ? Operator

    Conditional statements: if, if-else, switch, The ? Operator In PHP, conditional statements execute code based on the truth or false of conditions. PHP allows the following conditional statements, If statements. If……. Else statements. Switch statements. The ? operator. If statements: If conditions allow us to execute our program with a single true condition. Syntax: If(condition) { //to be executed block of code if the condition is true. } Flowchart:   Example 1:   Simple program with PHP. <?php $a=5; if($a%2==0) {             echo "Number is Even"; } ?> OUT-PUT Number is Even   Example 2: Program with PHP and HTML. <html> <body> <form method="POST" action="p1.php">   Name: <input type="text" name="fname">   <input type="submit"> </form...