search
HomeBackend DevelopmentPHP TutorialPHP(一)Environment and Types

PHP(1)Environment and Types
PHP(1)Environment and Types

1. Rebuild my win7 PHP environment
Download the latest version of PHP eclipse
http://mirror.cc.columbia.edu/pub/software/eclipse/technology/epp/downloads/release/helios/SR2/eclipse-php-helios-SR2-win32-x86_64.zip

Download the apache 2.2.21 version of windowns binary
http://mirrors.sonic.net/apache//httpd/binaries/win32/httpd-2.2.21-win32-x86-no_ssl.msi

Download the php source code
http://us.php.net/distributions/php-5.3.8.tar.gz
http://windows.php.net/downloads/releases/php-5.3.8-Win32-VC9-x86.zip
http://windows.php.net/downloads/releases/php-5.2.17-Win32-VC6-x86.zip

Install apache2.2.21

unzip php file php-5.3.8-Win32-VC9-x86.zip to the local dirver D:\tool\php-5.3.8
configure the apache configuration file  httpd.conf

LoadModule php5_module "d:/tool/php-5.3.8/php5apache2_2.dll"
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
Action application/x-httpd-php "d:/tool/php-5.3.8/php-cgi.exe"
AddType application/x-httpd-php .html
AddType application/x-httpd-php .htm
AddDefaultCharset UTF8
PHPIniDir "d:/tool/php-5.3.8"

create and change the php.ini file according to my php blog before. Make one file index.php to the htdoc directory of apache.
Visit this page http://localhost/index.php, everything is fine till now.

And I will configure this php environment work with eclipse php version according to my prevous blogs.

But this time, I directly change the directory to
DocumentRoot "C:/Users/Digby/workspace_php"

2. PHP grammer review


3. Types
Arrays
An array can be created by the array() language construct. It takes as parameters any number of comma-separated key => value pairs.
The key can only be an integer or string, value may be any value of any type.

$arr = array("foo" => 1, 12 => true);
echo gettype($arr[12]) . "
";
echo $arr[12];

output:
boolean
1

If a key is not specified for a value, the maximum of the integer indices is taken and the new key will be that value plus 1. If a key that already has an assigned value is specified, that value will be overwritten.

$arr = array(6 => 3, 5 => 4, 5, 6, "b" => 12, 6 =>100 );
echo $arr[6] . "
";
echo $arr[5] . "
";
echo $arr[7] . "
";
echo $arr[8] . "
";

output:
100
4
5
6

Creating/modifying with square bracket syntax
$arr = array(5 => 1, 12 => 2);
$arr[] = 56;   
// This is the same as $arr[13] = 56;
// at this point of the script
$arr["x"] = 42;
// This adds a new element to
// the array with key "x"
echo $arr[13] . "
";
unset($arr[5]); // This removes the element from the array
unset($arr);    // This deletes the whole array
if (NULL == $arr){
echo "empty arr!";
}
?>

As mentioned above, if no key is specified, the maximum of the existing integer indices is taken, and the new key will be that maximum value plus 1.

// Create a simple array.
$array = array(1, 2, 3, 4, 5);
print_r($array);
echo "
";
// Now delete every item, but leave the array itself intact:
foreach ($array as $i => $v) {
    unset($array[$i]);
    echo "unset $i => $v" . "
";
}
print_r($array);
echo "
";
// Append an item (note that the new key is 5, instead of 0).
$array[] = 6;
print_r($array);
// Re-index:
$array = array_values($array);
$array[] = 7;
echo "
";
print_r($array);

output:
Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 )
unset 0 => 1
unset 1 => 2
unset 2 => 3
unset 3 => 4
unset 4 => 5
Array ( )
Array ( [5] => 6 )
Array ( [0] => 6 [1] => 7 )

Useful functions
The unset() function allows removing keys from an array. Be aware that the array will not be reindexed.

The array_values() function can be used to 'remove and shift'.
$a = array(1 => 'one', 2 => 'two', 3 => 'three');
unset($a[2]);
/* will produce an array that would have been defined as
   $a = array(1 => 'one', 3 => 'three');
   and NOT
   $a = array(1 => 'one', 2 =>'three');
*/
print_r($a);
echo "
";
$b = array_values($a);
// Now $b is array(0 => 'one', 1 =>'three')
print_r($b);

Array do's and don'ts
$foo[bar] is wrong, but $foo['bar'] is right. This does not mean to always quote the key. Do not quote keys which are constants or variables, as this will prevent PHP from interpreting them.

examples:
$arr = array('fruit' => 'apple', 'veggie' => 'carrot');
// Correct
print $arr['fruit']."
";  // apple
print $arr['veggie']."
"; // 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']."
";  // apple
print $arr[fruit]."
";    // carrot

//it's inside a string. Constants are not looked for within strings
print "Hello $arr[fruit]
";

//braces surrounding arrays within strings allows constants
//to be interpreted
print "Hello {$arr[fruit]}
";    // Hello carrot
print "Hello {$arr['fruit']}
";  // Hello apple

references:
http://sillycat.iteye.com/blog/731677
http://sillycat.iteye.com/blog/768664
http://sillycat.iteye.com/blog/769110
http://sillycat.iteye.com/blog/770369

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
php怎么把负数转为正整数php怎么把负数转为正整数Apr 19, 2022 pm 08:59 PM

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

php字符串有没有下标php字符串有没有下标Apr 24, 2022 am 11:49 AM

php字符串有下标。在PHP中,下标不仅可以应用于数组和对象,还可应用于字符串,利用字符串的下标和中括号“[]”可以访问指定索引位置的字符,并对该字符进行读写,语法“字符串名[下标值]”;字符串的下标值(索引值)只能是整数类型,起始值为0。

php怎么除以100保留两位小数php怎么除以100保留两位小数Apr 22, 2022 pm 06:23 PM

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

php怎么读取字符串后几个字符php怎么读取字符串后几个字符Apr 22, 2022 pm 08:31 PM

在php中,可以使用substr()函数来读取字符串后几个字符,只需要将该函数的第二个参数设置为负值,第三个参数省略即可;语法为“substr(字符串,-n)”,表示读取从字符串结尾处向前数第n个字符开始,直到字符串结尾的全部字符。

php怎么根据年月日判断是一年的第几天php怎么根据年月日判断是一年的第几天Apr 22, 2022 pm 05:02 PM

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。

php怎么查找字符串是第几位php怎么查找字符串是第几位Apr 22, 2022 pm 06:48 PM

查找方法:1、用strpos(),语法“strpos("字符串值","查找子串")+1”;2、用stripos(),语法“strpos("字符串值","查找子串")+1”。因为字符串是从0开始计数的,因此两个函数获取的位置需要进行加1处理。

php怎么设置implode没有分隔符php怎么设置implode没有分隔符Apr 18, 2022 pm 05:39 PM

在PHP中,可以利用implode()函数的第一个参数来设置没有分隔符,该函数的第一个参数用于规定数组元素之间放置的内容,默认是空字符串,也可将第一个参数设置为空,语法为“implode(数组)”或者“implode("",数组)”。

php怎么判断有没有小数点php怎么判断有没有小数点Apr 20, 2022 pm 08:12 PM

php判断有没有小数点的方法:1、使用“strpos(数字字符串,'.')”语法,如果返回小数点在字符串中第一次出现的位置,则有小数点;2、使用“strrpos(数字字符串,'.')”语句,如果返回小数点在字符串中最后一次出现的位置,则有。

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft