echo "It is not a public company."; } echo "<br><br>"; ?> <br><br> <?php //function hw answers function cube($num) { return $num*$num*$num; } echo cube(3); echo "<br>"; echo cube(9); echo "<br><br>"; function power($num,$to) { $result = 1; for ($k=0; $k<$to; $k++) $result = $result*$num; return $result; } echo power(3,5); echo "<br>"; echo power (2,3); echo "<br><br>"; function pRG($person) { $greetings = array ("hi ", "hello ", "hola ");
<option value="Soccer">Soccer</option> <option value="Football">Football</option> <option value="Baseball">Baseball</option> </select><br> <input type="submit" name="submit" value="Subscribe to our mailing list!"> <!-- once you click submit, it will run HW 1.php --> </form> <p> <?php function cube($num) { return "$num^3 is ".($num*$num*$num);//ask how to superscript 3 } echo cube(3)."<br>"; echo cube(5)."<br>"; echo cube(2)."<br>"; ?> </p> <p> <?php function power($num, $pow) { return "$num^$pow is ". pow($num, $pow); } echo power(2,3)."<br>"; echo power(3,4)."<br>"; echo power(15,15)."<br>"; ?> </p>
<?php /** * return.php * * David J. Malan * malan@harvard.edu * * Cubes a variable. * * Demonstrates use of parameter and return value. */ $x = 2; printf("x is now %d\n", $x); printf("Cubing...\n"); $x = cube($x); printf("Cubed!\n"); printf("x is now %d\n", $x); /** * Cubes argument. */ function cube($n) { return $n * $n * $n; }
$leet[$k] = "7"; } } return $leet; } $result = ""; if (isset($_POST['submit'])) { $contents = htmlspecialchars($_POST['text']);//protection from html coding input on the text box $result = leetify($contents); } // PHP has a function called INCLUDE that allows you to use your own function from a php file to all other php files $result2 = ""; if (isset($_POST['submitit'])) { $content = htmlspecialchars($_POST['number']);//protection from html coding input on the text box $result2 = cube($content); } ?> <h1>THE LEETIFICATOR</h1> <p>Enter some text that you would like to convert to <s>hacker-speak</s> h4x0r-sp33k.</p> <form action="Class 5 activity.php" method="POST"> <input type="text" name="text"> <input type="submit" name="submit"><br> </form><br><br> <p><strong>Result</strong>: <?php echo $result; ?> </p> <br>
<?php require_once './namespace.php'; require_once './namespace2.php'; require_once './namespace3.php'; use Oreilly\Php7\UpToSpeed\{Nouns\Language, Nouns\Operator, Verbs\Possess}; use Oreilly\Php7\UpToSpeed\Common\{DoSomething, const PIE, const LOCATION, function doubleIt, function cube}; $number = 4; echo '<p>' . LOCATION . ' is a great place to live.</p>'; echo "<p>Twice {$number} is " . doubleIt($number) . ", but cubed, it's " . cube($number) . '.</p>'; $obj = new DoSomething(); echo '<p>Yum, ' . PIE . '!</p>';
<?php function cube($nombre) { return $nombre * $nombre * $nombre; } echo cube($_GET['a']);