PHP Week 2

<?php
//two input words joined by 'and'
$noun1=$argv[1];
$noun2=$argv[2];
echo "\n$noun1 and $noun2\n\n"
?>

Fany-Savinas-Mac:PHP Fany$ php twonoun.php dog cat

dog and cat

------

<?php
//add, substract, multiply and divide two input numbers
$number1=$argv[1];
$number2=$argv[2];
$sum_total_one = $number1 + $number2;
$sum_total_two = $number1 - $number2;
$sum_total_three = $number1 * $number2;
$sum_total_four = $number1 / $number2;
echo "\n$number1 + $number2= $sum_total_one\n";
echo "$number1 - $number2= $sum_total_two\n";
echo "$number1 x $number2= $sum_total_three\n";
echo "$number1 / $number2= $sum_total_four\n\n"
?>

Fany-Savinas-Mac:PHP Fany$ php numbermaths.php 5 10

5 + 10= 15
5 - 10= -5
5 x 10= 50
5 / 10= 0.5

------

<?php
//an input word repeated an input number of times 
$string=$argv[1];
$repeat=$argv[2];
echo str_repeat("\n$string\n\n",$repeat);
?>

Fany-Savinas-Mac:PHP Fany$ php repeat.php animals 3

animals

animals

animals

This entry was posted in Computing and tagged , , , , , . Bookmark the permalink.

Leave a reply