86年属什么的| 玉屏风颗粒主治什么| 右下腹痛挂什么科| 今年28岁属什么生肖| 友谊是什么意思| 什么是地包天牙齿| 粥样动脉硬化是什么意思| 牙碜是什么意思| 前列腺钙化有什么症状| qeelin是什么牌子| 耳朵后面痒是什么原因| 榴莲有什么作用| 大林木是什么数字| 望周知是什么意思| 2008年是什么年| 痛风应该挂什么科| advil是什么药| 孔雀的尾巴像什么| 宗人府是干什么的| 落叶像什么飘落下来| 大限将至什么意思| 双肾囊肿有什么危害| 豆角没熟中毒什么症状| 芝士是什么| 双侧骶髂关节致密性骨炎是什么病| 三点水开念什么意思| 谷氨酰转肽酶高是什么原因| 出行是什么意思| 什么西瓜| 为什么人会做梦| 三个大是什么字| 反复口腔溃疡是什么病的前兆| 痔疮吃什么药好得快| 磨牙是什么原因怎么治疗| 一什么颜色| 建档需要准备什么资料| 软件开发属于什么行业| 小翅膀车标是什么车| 感染hpv有什么症状| 机能鞋是什么意思| 鼻基底填充用什么材料比较好| 免贵姓是什么意思| 2月12日什么星座| 12月15号是什么星座| 抄手是什么| 升阳是什么意思| 浅表性胃炎用什么药| 手信是什么意思| 玻璃五行属什么| 财迷是什么意思| 吃羊肉有什么好处| 金融办是什么单位| 冬瓜炖什么好吃| 什么什么满门| 0z是什么单位| 足本是什么意思| 开柙出虎是什么意思| 钼靶检查是什么意思| 泡脚什么时候泡最好| 天麻种植需要什么条件| marni是什么牌子| 怀孕早期需要注意什么| 岳云鹏为什么这么火| 青春永驻是什么意思| 身份证是什么字体| 含漱是什么意思| 心脏病是什么原因引起的| 肚脐眼下面疼是什么原因| 狗狗拉肚子是什么原因| 冰心原名叫什么| 船舷是什么意思| 糖水是什么| 洁颜蜜是什么| 偶见是什么意思| 黄瓜敷脸有什么功效与作用| 什么秒必争| 东北和山东有什么区别| 四级军士长是什么级别| 网球肘用什么膏药效果好| 离家出走需要准备什么| 岁月如歌什么意思| 午餐肉是什么肉做的| hca是什么意思| low什么意思| 罗贯中和施耐庵是什么关系| 六七是什么意思| 骨折吃什么好的快| 什么书比较好| 锋字五行属什么| 家里养什么宠物好| 小孩睡觉打呼噜是什么原因| affairs是什么意思| 1992年属猴的是什么命| 人脉是什么意思| 鹿晗的粉丝名叫什么| 玄关挂什么装饰画好| 戏谑什么意思| 乌灵参是什么东西| 流鼻血什么原因| 感冒喝什么汤| 玫瑰花泡水喝有什么功效| 为什么总是做噩梦| 骨折什么症状| 申时五行属什么| 肝胆胰腺属于什么科| 香砂六君丸治什么病| 胰岛素是什么器官分泌的| 市人大副主任什么级别| sch是什么意思| 什么东西掉进水里不会湿| 流苏是什么东西| 泾渭分明是什么意思| u1是什么意思| 非甾体抗炎药是什么意思| 香港奶粉为什么限购| 喝普洱茶有什么功效| 情感障碍是什么意思| 属兔的和什么属相最配| 血糖高的人可以吃什么水果| 喝茶为什么睡不着觉| 什么叫六亲| 螨虫长什么样| 来袭是什么意思| 扁桃体发炎用什么药| 吃柿子有什么好处和坏处| 中暑什么感觉| 冷沉淀是什么| 眼睛疼吃什么药| 1月11日什么星座| 一马平川是什么生肖| 夕阳西下是什么意思| 喝椰子粉有什么好处| 什么案件才会出动便衣| 夏天适合用什么护肤品| fps是什么意思| 出什么入什么| 犹太人是什么| 破代表什么生肖| 处女座男和什么座最配对| 什么是一线城市| 什么叫培根| 受益匪浅的意思是什么| 慌张是什么意思| 掉头发什么原因| 门前的小树已成年是什么歌| 蓝天白云是什么生肖| 关照是什么意思| 酸梅汤与什么相克| 生殖激素常规检查是查什么的| 乌黑对什么| 7月15是什么节| 唇炎属于什么科| 大娘的老公叫什么| 黄芪什么功效| 比肩什么意思| 项羽字什么| 嘎哈是什么意思| edc是什么| 宫颈炎和阴道炎有什么区别| 捡到狗狗代表什么预兆| 小孩晚上睡觉出汗是什么原因| 金鸡独立是什么意思| 脊髓损伤有什么症状| 玉竹有什么功效| 碧玺是什么| 成熟是什么意思| 疾控中心是干什么的| 做梦梦到吵架是什么意思| 费心是什么意思| iss是什么意思| 大姨妈不能吃什么水果| 出库是什么意思| 白露是什么季节的节气| 鬼最怕什么东西| 甩货是什么意思| 1893年属什么生肖| 送男朋友什么礼物合适| 副局级干部是什么级别| 正值当年什么意思| 梦见找鞋子是什么意思| 胃肠湿热吃什么中成药| 夏季养什么脏腑| 为什么会堵奶| ab和b型血生的孩子是什么血型| 头晕恶心呕吐是什么原因| 五更泻吃什么药| 不举什么意思| 卷帘大将是干什么的| 什么字永远写不好| 肩胛骨发麻是什么原因| 打蛋器什么牌子好| 盼头是什么意思| 中国发明了什么| 什么败走华容道不出所料| 太平鸟属于什么档次| 霉菌反复发作是什么原因| 喝酒脸红是缺少什么酶| 香菜炒什么好吃| o和b型生的孩子是什么血型| 心率过缓有什么危害| 什么叫自慰| evisu是什么牌子| 呼吸衰竭是什么意思| 玻璃心什么意思| 角膜炎滴什么眼药水| 慕字五行属什么| 小便白细胞高是什么原因| 化疗后吃什么增强免疫力| 拔萝卜什么意思| 蓁是什么意思| hf是什么| 雏凤是什么意思| 四百多分能上什么大学| 水镜先生和司马懿是什么关系| 苦瓜泡酒有什么功效和作用| 复方氨酚烷胺片是什么药| 脚背肿是什么原因引起的| 手抖什么原因| 晕3d什么症状| 负数是什么| 项韧带钙化是什么意思| 花椒有什么功效与作用| 骨密度挂什么科| 牛肉和什么炒好吃| 炒菜用什么油比较好| 老人脚肿是什么征兆| 什么枝条| 口苦吃什么中药| 放射治疗是什么意思| 蒸馏水敷脸有什么作用| 棘突是什么意思| 什么眼型最好看| 四川代表什么生肖| 肺热会引起什么症状| 胃疼屁多是什么原因| 什么都不是| ag是什么意思| 视频脑电图能检查出什么| 深圳市市长是什么级别| 1983年属什么生肖| 势利眼是什么意思| 玉兰油属于什么档次| 头层牛皮除牛反绒是什么意思| 马口鱼是什么鱼| afd是什么意思| 高血压适合做什么运动| 五液是指什么| 千什么一发| 柒牌男装什么档次| cet是什么意思| 放我鸽子是什么意思| 腹胀做什么检查效果好| 皮肤上有小白斑点是什么原因| 死间计划到底是什么| 什么叫尿潴留| 国防部部长是什么级别| 六月初二是什么日子| 猕猴桃什么季节成熟| 植物园有什么植物| 属鸡的跟什么属相最配| 公子是你吗是什么歌| 衣原体检查是什么| 鲈鱼不能和什么一起吃| 什么东西补血效果最好| 百度

谁能代表真正的重庆?大概只有未曾变过的,山...

< PHP
百度 金茂是带着城市建设使命感而来的,要为这座高速发展的“新一线”城市带来绿色、科技的金茂府。

Variables, as mentioned briefly in Introduction to PHP, are a significant feature of any programming language. They can be used to store all forms of data, and are generally required to perform multiple manipulations on data not hard-coded into a script. This lesson will introduce the basics of variables in PHP.

Basic syntax

edit

In PHP, all variables can be identified by the $ at the beginning of their name. Variables name generally start with a lowercase letter, however this can vary for special variables, which will be explained later. To understand how variables work, take this example:

<?php
echo 'Hello world!';
?>

Here is the same example using variables instead:

<?php
$message = 'Hello world!';
echo $message;
?>

Dynamic typing

edit

A number of other high profile languages (C and C++, for example) use static variable typing. This means that variables have to be given a data type (e.g. number, string of letters, boolean TRUE or FALSE) that will remain the same until they are destroyed.

This is often useful, however PHP does away with static typing and dynamically converts variable types when needed. As explained in the Introduction to PHP article, PHP has different syntax for numbers and strings, however due to PHP's dynamically typed nature, strings can be treated as numbers when needed. Take the following example:

<?php
$input = '42';
$thevalue = $input * pi(); // Will multiply 42 by pi to (by default) 14 decimal places.
echo $thevalue; // This should return something along the lines of 131.946891451
?>

In this instance, we are multiplying the number 42 (in a string variable) by pi to a certain number of decimal places. PHP automatically converts '42' to 42 (a string to an integer). Conversion of clearly abnormal data can produce unexpected results, however. Take the following example:

<?php
$input = '4string2';
// Should multiply 42 by pi, but will produced unexpected results
$thevalue = $input * pi();
echo $thevalue;
?>

Depending on the PHP configuration, PHP may convert '4string2' to integer values before multiplying it by pi, with unexpected results. (On some PHP versions everything after the '4' is ignored and the result is approximately 12.56)

Variable types

edit

These are the main types of variables you will be dealing with:

  • int – Short for integer. Holds any integer, i.e. a whole numerical value (no decimal places—however, if an int is assigned a number with a decimal place, it will be converted to a float automatically)
  • float – Abbreviation of floating point value. Holds any integer with a decimal place, to a certain precision (generally 32 digits)
  • double – Abbreviation of double precision floating point. Same as above except with far more precision—however, a double value also takes up twice as much memory (generally 8 bytes—obviously insignificant on modern servers)
  • string – Holds any array of characters, i.e. a sentence (or two). Generally has an infinite length; however, for compatibility with older servers, limit the size of strings to 32768 characters. Strings are surrounded with single quotes when used in PHP.
  • boolean – Can either be true or false, many functions return true or false

Declaration

edit

In a lower-level language like C++, the declaration of the type of each variable is needed. For example, the following code in PHP:

<?php
$a = 'Stuff';
?>

Does not explicitly define the type of variable a. Of course, the PHP runtime environment recognizes during execution of this line that the programmer provided a string literal as the value for the variable. If you want to do the same in C++, you would would have to explicitly declare the variable type:

char[6] a;
a = "Stuff";

Additional equivalent statements combining declaration and initialization of a variable with the same value would be:

char* a = "Stuff"; // using char pointer
char b[] = "Stuff"; // using char array with string literal initialization
char c[] = { 'S', 't', 'u', 'f', 'f', '\0' }; // using char array with array initialization

Notice that C++ requires explicit variable declaration (including variable type) whereas PHP does not. However, it is good practise to declare all variables, as if they are not declared PHP defaults their value to FALSE (0, empty etc.). This is because PHP is a dynamically typed language, and as a result neither type casting nor declaration is enforced. The following is possible:

<?php
$a;
?>

Scope

edit

Scope refers to what can actually modify a variable, e.g:

<?php
$var = 1;
require 'another_page.php';
?>

The page 'another_page.php' has full access to the variable 'var'.

<?php
$var = 'Test';
function test()
{
 echo $var;
}
test();
?>

OUTPUT-> The above would output nothing, since functions have their own scope, variables outside that scope would not be available.

Globals

edit

You can force functions to access other variables by using the global keyword, e.g:

<?php
$var = 'Test';
function test()
{
 global $var;
 echo $var;
}
test();
?>

Would output: Test

Or you can use the $GLOBALS array, like this:

<?php
$GLOBALS['var'] = 'Test';
function test()
{
 echo $GLOBALS['var'];
}
test();
?>

Static Variables

edit

Static variables exist within a function and are saved after the function executes, e.g:

<?php
function increment()
{
 static $a = 0;
 echo $a;
 $a++;
}
increment(); // 0
increment(); // 1
increment(); // 2
increment(); // 3
?>

If the variable 'a' was not static, it would echo 0 each time.

Referencing

edit

On a sidenote, a less used feature of PHP (and, indeed, many lower level programming languages) is memory address referencing. The idea is that every variable is stored at a certain address in memory. Now, say you wanted to have a variable that always remained the same values as another, you could just store point it at the same address - any changes at that address, i.e. any change to the value of the first variable, would be reflected in the other variable. Examine the following:

<?php
$a = 'Stuff';
$b = &$a; // $b is pointed to $a
$a = 'Stuff2.0'; // $b is now also 'Stuff2.0';
$b = 'Stuff3.0'; // $a is now also 'Stuff3.0';
?>

Learning sessions

edit

None available at present.

ccs是什么意思 幽门螺杆菌用什么药 益母草煮鸡蛋有什么功效 有氧运动是指什么 格局小是什么意思
手麻木什么原因 妈妈生日送什么礼物好 为什么要穿内裤 蜜蜡脱毛有什么危害吗 崩漏带下是什么症状
孕早期胎停有什么症状或征兆吗 为什么叫汉族 水可以变成什么 大肠杆菌是什么 天贝是什么东西
一个h是什么牌子 钙化淋巴结是什么意思 抗链球菌溶血素o偏高是什么原因 伽马刀是什么意思 梦见家里好多蛇是什么预兆
3.5是什么星座hcv9jop1ns8r.cn 左旋肉碱是什么hcv8jop8ns1r.cn 男性硬下疳是什么样子hcv8jop1ns5r.cn 嫁给香港人意味着什么hcv9jop2ns7r.cn 行驶证和驾驶证有什么区别hcv9jop4ns0r.cn
低血压低是什么原因hcv8jop1ns7r.cn 1938年中国发生了什么hcv9jop8ns2r.cn 羊与什么相冲hcv8jop2ns0r.cn 最近我和你都有一样的心情什么歌xinjiangjialails.com 什么明月hcv9jop5ns7r.cn
屠苏是什么意思hcv8jop5ns7r.cn 澳门用什么币种hcv9jop0ns5r.cn 虫离念什么hcv9jop4ns8r.cn 打喷嚏漏尿是什么原因hcv8jop6ns5r.cn 骨髓炎是什么病hcv8jop4ns7r.cn
黄芪丹参山楂泡水有什么功效hcv9jop5ns8r.cn g750和au750有什么区别hcv8jop7ns0r.cn 减胎对另一个胎儿有什么影响hcv9jop4ns4r.cn 皮肤长癣是什么原因bfb118.com 刮痧是什么hcv9jop5ns0r.cn
百度