User Tools

Site Tools


php_variables

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
php_variables [2024/10/06 05:12] appledogphp_variables [2024/10/06 05:16] (current) appledog
Line 20: Line 20:
 </Code> </Code>
  
-=== Integers +== Operations 
-We can also store numbers.+We can add variables together. 
 + 
 +<Code:PHP> 
 +<?php 
 + 
 + $a = readLine("a = "); 
 + $b = readLine("b = "); 
 + 
 + echo $a . " + " . $b . " = " . $a+$b . "\n"; 
 + 
 +?> 
 +</Code> 
 + 
 + 
 +== Testing variables with IF 
 +We can also determine what to do based on what's in a variable. 
 + 
 +<Code:PHP> 
 +<?php 
 + 
 + $name = readLine("What is your name? "); 
 + $fruit = readLine("What is your favourite fruit? "); 
 + 
 + if ($fruit == "poo") { 
 + echo "Ewwwwww!\n"; 
 + echo $name . " is bad!\n"; 
 + } else if ($fruit == "banana") { 
 + echo "{$name} is good.\n"; 
 + echo "I also like {$fruit}. Yum!\n"; 
 + } else { 
 + echo "Hello, {$name}.\n"; 
 +
 + 
 +?> 
 +</Code> 
 + 
 + 
 +== Integers 
 +We can also store numbers and do operations on those numbers.
  
 <Code:PHP> <Code:PHP>
Line 34: Line 72:
 ?> ?>
 </Code> </Code>
 +
php_variables.1728191565.txt.gz · Last modified: 2024/10/06 05:12 by appledog

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki