1. Check MAC Software Installation
Check the version of apache
>sudo apachectl -v
Server version: Apache/2.2.26 (Unix) Server built: Dec 10 2013 22:09:38
Start the Server
>sudo apachectl start
Uncomments this line is /etc/apache2/httpd.conf
LoadModule php5_module libexec/apache2/libphp5.so
Prepare the configuration
>sudo cp php.ini.default php.ini
Prepare the php file
>cat /Library/WebServer/Documents/info.php
<?php phpinfo(); ?>
Visit the page http://localhost/info.php PHP Version 5.4.24
I already have my mysql.
I download the file http://us1.php.net/distributions/php-5.5.12.tar.gz
2. PHP Grammer
Link the working directory under apache document root
>sudo ln -s /Users/carl/work/easy/easyphp /Library/WebServer/Documents/easyphp
If we did not set the key, it will be the max key + 1.
unset($arr[5]); // This removes the element from the array
unset($arr); // This deletes the whole array
// Create a simple array.
$array = array(1, 2, 3, 4, 5);
print_r($array);
echo "<br />";
// Now delete every item, but leave the array itself intact:
foreach ($array as $i => $v) {
unset($array[$i]);
echo "unset $i => $v" . "<br />";
}
The array_values() function can be used to 'remove and shift’.
$arr = array('fruit' => 'apple', 'veggie' => 'carrot');
// Correct
print $arr['fruit']."<br />"; // apple
print $arr['veggie']."<br />"; // carrot
// This defines a constant to demonstrate what's going on. The value 'veggie'
// is assigned to a constant named fruit. define('fruit', 'veggie');
// Notice the difference now
print $arr['fruit']."<br />"; // apple
print $arr[fruit]."<br />"; // carrot
<?php
$a_bool = TRUE; // a boolean
$a_str = "foo"; // a string
$a_str2 = 'foo'; // a string
$an_int = 12; // an integer
echo gettype($a_bool); // prints out: boolean
echo '<br />';
echo gettype($a_str); // prints out: string
// If this is an integer, increment it by four
if (is_int($an_int)) {
$an_int += 4;
}
echo "<br />";
echo $an_int;
// If $bool is a string, print it out
// (does not print out anything)
if (is_string($a_bool)) {
echo "String: $a_bool";
}
?>
echo <<<EOT
My name is "$name". I am printing some $foo->foo.
Now, I am printing some {$foo->bar[1]}.
This should print a capital 'A': \x41
EOT;
?>
The above example will output:
My name is "MyName". I am printing some Foo.
Now, I am printing some Bar2.
This should print a capital 'A': A
References:
PHP(1) ~ (2) http://sillycat.iteye.com/blog/1543227 win7 php installation and php types http://sillycat.iteye.com/blog/1638638 MAC php installation
http://sillycat.iteye.com/blog/1040371 PHP installation on ubuntu