Skip to content

Instantly share code, notes, and snippets.

@ning415
Created March 19, 2018 05:15
Show Gist options
  • Save ning415/c5380b2a5ad006d9e82334ee626ebfb9 to your computer and use it in GitHub Desktop.
Save ning415/c5380b2a5ad006d9e82334ee626ebfb9 to your computer and use it in GitHub Desktop.
cpe207-Basic Web Programming
<?php
//echo ini_get('upload_max_filesize');
phpinfo();
?>
<?php
$next=1;
echo 'next number is '.$next++;
echo "<br>";
$next=1;
echo 'next number is '.++$next;
echo "<br>";
?>
<?php
#index array
$cars = array("Volvo", "BMW", "Toyota");
echo 'I like '. $cars[0].' , '.$cars[1].' and '.$cars[2];
echo '<br>';
echo '<br>';
$arrlength=count($cars);
for($x=0;$x<$arrlength;$x++) {
echo $cars[$x].'<br>';
}
echo '<br>';
?>
<?php
#assoc array
$age['Peter'] = 35;
$age['Ben'] = 43;
$age['Joe'] = 53;
echo 'Peter is ' . $age['Peter'].' years old.';
echo '<br>';echo '<br>';
foreach($age as $key=>$value)
{
echo 'Key= '.$key. ' , Value= '.$value.'<br>';
}
?>
<?php
#multi array
$marks = array(
"john" => array (
"course" => "physics",
"point" => 32
),
"zara" => array (
"course" => "physics",
"point" => 39
)
);
echo '<pre>';
print_r($marks);
echo '</pre>';
echo '<br>';
echo 'John get '. $marks['john']['point'] .' point in '. $marks['john']['course'] ;
?>
<?php
#local variable
function assignx () {
$x = 0;
echo "$x inside function is $x. <br>";
}
$x = 4;
assignx();
echo "$x outside of function is $x. <br>";
?>
<?php
#global variable
function addit() {
GLOBAL $somevar;
$somevar++;
echo "Somevar is $somevar <br>";
}
$somevar = 15;
addit();
?>
<?php
#static variable
function keep_track() {
STATIC $count = 0;
$count++;
echo 'count is '.$count.'<br>';
}
$count=9;
keep_track(); // 1
keep_track(); // 2
keep_track(); // 3
?>
<?php
echo "My heading ";
print "with style";
?>
<?php
echo "<h1>My heading with style</h1><br>";
print "<h2>My heading</h2>";
?>
<?php
$month='March';
echo 'current variable type is <b>'.gettype($month) . "</b><br>";
$month=3;
echo 'new variable type is <b>'.gettype($month) . "</b><br>";
$month="3";
echo "month \'s value is $month , variable type is <b>".gettype($month) . "</b><br>";
$monthId=(int)$month;
echo "monthId \'s value is $monthId , variable type is <b>".gettype($monthId) . "</b><br>";
?>
<?php
$a = 'hello';
$$a = 'world';
echo "$a $hello";
echo '<br>';
${'a' . 'b'} = 'hello there';
echo $ab;
?>
<?php
define('FRUIT','apple',true);
ECHO FRUIT;
echo '<br>';
ECHO fruit;
echo '<br>';
?>
<?php
echo "This line number is : " .__LINE__;
echo "<br>";
echo "The full path of this file is: " . __FILE__;
echo "<br>";
echo dirname(__FILE__);
echo "<br>";
?>
<?php
$variable='data';// \'s value
echo 'My $variable will not print';
echo "<br>";
echo "My $variable will print";
?>
<?php
$x=100;
$y='100';
if($x===$y)
echo 'equal';
else
echo 'not equal';
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment