Contents
-----
Flow Chart:
-----
Pseudo Code:
1. BEGIN
2. INPUT var1, var2
3. PRINT var1+var2
4. END
-----
PHP Language sample code:
sumvariables.php
|
<?php
//assume user input 1,2
$var1=$_GET["input1"];
$var2=$_GET["input2"];
echo $var1+$var2;
?>
|
-----
PHP Language sample output:
-----
Flow Chart:
-----
Pseudo Code:
1. BEGIN
2. INPUT var1, var2
3. PRINT var1 x var2
4. END
-----
PHP Language sample code:
multiplyvariables.php
|
<?php
//assume user input 1,2
$var1=$_GET["input1"];
$var2=$_GET["input2"];
echo $var1*$var2;
?>
|
-----
PHP Language sample output:
-----
Flow Chart:
-----
Pseudo Code:
1. BEGIN
2. INPUT var1, var2
3. IF var2=0
4. THEN PRINT "Error. Division by zero."
5. ELSE PRINT var1/var2
6. END
-----
PHP Language sample code:
dividevariables.php
|
<?php
//assume input 1,0
$var1=$_GET["input1"];
$var2=$_GET["input2"];
if ($var2==0)
{ echo "Error. Division by zero.";}
else
{ echo $var1/$var2;}
?>
|
-----
PHP Language sample output:
-----
Flow Chart:
-----
Pseudo Code:
1. BEGIN
2. PRINT "Start counting."
3. FOR i LOOP := 1 to 3
4. PRINT i
5. END LOOP
6. PRINT "Done."
7. END
-----
PHP Language sample code:
countnumbers.php
|
<?php
echo "Start counting."."<br/>";
for ($x=$_GET["input1"]; $x<=$_GET["input2"]; $x++) {
echo $x."<br/>";
}
echo "Counting done."."<br/>";
?>
|
-----
PHP Language sample output:
-----
Flow Chart:
(Note: Change Init to Input)
-----
Pseudo Code:
1. BEGIN
2. INPUT ARRAY arr[5] TO CONTAIN VALUES 1,2,3,4,5
3. PRINT "Displaying array values."
4. FOR i := 1 to 5
5. PRINT arr[i]
6. END FOR LOOP
7. PRINT "Done."
8. END
-----
PHP Language sample code:
displayarrayvalues.php
|
<?php
$str=$_GET["input1"];
$arr=explode(",",$str);
echo "Display array values"."<br/>";
for ($x=0; $x<=4; $x++) {
echo $arr[$x]."<br/>";
}
echo "Done"."<br/>";
?>
|
-----
PHP Language sample output:
-----
Note:
This tutorial demonstrates the steps to edit an array value. The program displays the array values before and after the edit is done. There are code redundancies here. Ignore this for now.
-----
Flow Chart:
-----
Pseudo Code:
1. BEGIN
2. INITIALIZE ARRAY arr[i] WITH VALUES 1,2,3,4,5
3. FOR i := 1 to 5
4. PRINT arr[i]
5. END FOR LOOP
6. INPUT indexnumber
7. INPUT arrayvalue
8. arr[indexnumber] = arrayvalue
9. FOR i := 1 to 5
10. PRINT arr[i]
11. END FOR LOOP
12. END
-----
PHP Language sample code:
editarrayvalues.php
|
<?php
$arr=array('a','b','c','d','e');
echo "Display array values"."<br/>";
for ($x=0; $x<=4; $x++) {
echo $arr[$x]."<br/>";
}
echo "Done"."<br/>";
$indexnumber=$_GET['input1'];
$arrayvalue=$_GET['input2'];
$arr[$indexnumber]=$arrayvalue;
echo "Display array values"."<br/>";
for ($x=0; $x<=4; $x++) {
echo $arr[$x]."<br/>";
}
echo "Done"."<br/>";
?>
|
-----
PHP Language sample output:
-----
Flow Chart:
-----
Pseudo Code:
1. BEGIN displaydata
2. FOR all item in array PRINT item values
3. END displaydata
1. BEGIN displaydata
2. FOR all item in array PRINT item values
3. END displaydata
1. BEGIN updatedata
2. INPUT indexnumber, arrayvalue
3. arr[indexnumber]=arrayvalue
2. INPUT indexnumber, arrayvalue
3. arr[indexnumber]=arrayvalue
4. END updatedata
1. BEGIN main
2. CALL displaydata
3. CALL updatedata
4. CALL displaydata
5. END main
2. CALL displaydata
3. CALL updatedata
4. CALL displaydata
5. END main
-----
PHP Language sample code:
Note: We are using parameter passing here; passing by value=$arr, passing by reference=&$arr
modularprogram.php
|
<?php
$arr=array('a','b','c','d','e');
function displayData($arr){
echo "Display array values"."<br/>";
for ($x=0; $x<=4; $x++) {
echo $arr[$x]."<br/>";
}
echo "Done"."<br/>";
}
function updateData(&$arr){
echo "Updating Data..."."<br/>";
global $arr;
$indexnumber=$_GET['input1'];
$arrayvalue=$_GET['input2'];
$arr[$indexnumber]=$arrayvalue;
}
displayData($arr);
updateData($arr);
displayData($arr);
?>
|
-----
PHP Language sample output:
Nice Blog , This is what I exactly Looking for , Keep sharing more blog .
ReplyDeleteHire PHP Framework Developers in India