X

PHP Server Side Scripting Language.

The  Hypertext Preprocessor (PHP) is a programming language that allows web developers to create dynamic content that interacts with databases.

 

PHP is a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML.

It is a server side scripting languages.

It is a powerful tool for making dynamic and interactive Web pages.

PHP is a widely-used, free, and efficient alternative to competitors such as Microsoft’s ASP.

1. Explain php array type with examples?

Answer:-

PHP Indexed Arrays:

An array is a special variable, which can hold more than one value at a time.

Example:    $cars=array(“Volvo”,”BMW”,”Toyota”);

PHP Associative Arrays:

Associative arrays are arrays that use named keys that you assign to them.

Example:  $age=array(“Peter”=>”35″,”Ben”=>”37″,”Joe”=>”43″);

Multidimensional Arrays:

An array can also contain another array as a value, which in turn can hold other arrays as well. In such a way we can create two- or three-dimensional arrays.

2. Explain php superglobals variable?

Answer:-

Several predefined variables in PHP are “superglobals”, which means they are available in all scopes throughout a script. There is no need to do global $variable; to access them within functions or methods.

$GLOBALS    $_SERVER   $_GET   $_POST   $_FILES   $_COOKIE   $_SESSION   $_REQUEST   $_ENV

3. php conditional and looping syntax with examples?

Answer:-

Conditional:

The if Statement

[php]

if (condition)

{

code to be executed if condition is true;

}

The if…else Statement

if (condition)

{

code to be executed if condition is true;

}

else

{

code to be executed if condition is false;

}

[/php]

The if…else if….else Statement

[PHP]

if (condition)

{

code to be executed if condition is true;

}

else if (condition)

{

code to be executed if condition is true;

}

else

{

code to be executed if condition is false;

}

[/PHP]

The PHP Switch Statement

[PHP]

witch (n)

{

case label1:

code to be executed if n=label1;

break;

case label2:

code to be executed if n=label2;

break;

default:

code to be executed if n is different from both label1 and label2;

}

[/PHP]

Looping:

The While Loop

[PHP]

while (condition)

{

code to be executed;

}

The Do…While Loop

do

{

code to be exected;

}

while (condition);

The For Loop

for (initialization; condition; increment)

{

code to be executed;

}

The Foreach Loop

foreach (array as value)

{

code to be executed;

}

foreach (array as key => value)

{

code to be executed;

}

[/PHP]

Break and Continue Statements

Examples below show how to use the Break statement:

echo ”

Example of using the Break statement:

[PHP]

for ($i=0; $i<=10; $i++) {

if ($i==3){break;}

echo “The number is “.$i;

echo ”

}

echo ”

[/PHP]

One more example of using the Break statement:

[PHP]

$i = 0;

$j = 0;

while ($i < 10) {

while ($j < 10) {

if ($j == 5) {break 2;} // breaks out of two while loops

$j++;

}

$i++;

}

echo “The first number is “.$i.”

“;

echo “The second number is “.$j.”

“;

?>

[/PHP]

he Continue statement terminates execution of the block of statements in a While or For loop and continues execution of the loop with the next iteration:

echo ”

Example of using the Continue statement:

[PHP]“;

for ($i=0; $i<=10; $i++) {

if (i==3){continue;}

echo “The number is “.$i;

echo ”

“;

}

?>

[/PHP]

CodeKul: About CodeKul - Codekul is leading software development training institute in Pune which provides Online, Classroom & Video Series training to the Coders who are interested to learn things practically and want to solve problems in the world. Following Courses are Offered at CodeKul - - Mobile Application Development (Android, Kotlin, iOS) - Website Application Design & Development - Database Technology - Framework Technology - Software Testing - Unity3d / Game development - Full Stack Development - Mean Stack Development
Related Post