通告是什么意思| 白羊座后面是什么星座| 鞋履是什么意思| 暮春是什么时候| 长期失眠应该吃什么药| 电商五行属什么| ccs是什么意思| 老汉推车是什么意思| 胃酸胃胀吃什么药| 什么是题材股| 眷念是什么意思| 腺样体肥大有什么症状| 蜂蜜不能和什么食物一起吃| 什么东西能美白| 刚感染艾滋病什么症状| 屁特别多是什么原因| 戊戌是什么意思| pgr是什么意思| 盲目是什么意思| 非钙化斑块是什么意思| 400年前是什么朝代| 益生菌吃了有什么好处| 乳糖不耐受喝什么奶粉| 茶叶含有什么成分| 排卵试纸什么时候测最准| 北伐是什么意思| 戒备心是什么意思| 看见乌鸦有什么预兆| 脑袋疼是什么原因| 牛角尖是什么意思| 子宫附件是什么| bc是什么牌子| 腰间盘突出挂什么科室| 六月底是什么星座| 下元节是什么节日| pnp是什么意思| 孕检无创是检查什么的| 右肺中叶小结节是什么意思严重吗| 下作是什么意思| 善根是什么意思| 西游记什么朝代写的| 茄子吃多了有什么坏处| 大便失禁吃什么药| 蝙蝠是什么类| 宝宝便秘吃什么好| 皈依有什么好处| 棘突是什么意思| 洗牙有什么好处和坏处| 什么睡姿有助于丰胸| 什么的麦子| 沐什么意思| 冒节子是什么东西| 上半身胖属于什么体质| 09年的牛是什么命| 利空是什么意思| 预设是什么意思| 你好是什么意思| 什么是小数| lv属于什么档次| 剖腹产后可以吃什么| eos是什么| 查传染病四项挂什么科| 有什么意思| 梦见在天上飞是什么意思| 共济失调是什么意思| lof是什么意思| 为什么会怀孕| 3月1日是什么星座| 玉米不能和什么食物一起吃| 机体是什么意思| 什么脑袋| afd是什么意思| 有张有弛是什么意思| 硬皮病是什么病| 为什么长斑| 坐久了脚肿是什么原因| 空调多少匹什么意思| 1999年属什么生肖| 皓五行属什么| 闰年是什么| 八院是什么医院| 吃什么对肺结节好| 特别容易饿是什么原因| aa是什么病| 牙膏尾部的颜色代表什么意思| 脾肾阳虚吃什么药| 体检前一天晚上吃什么| 黄体破裂是什么症状| 孩子晚上睡觉磨牙是什么原因| 哺乳期吃什么水果好| 瘦脱相是什么意思| 流口水是什么原因引起的| 碱水对人有什么危害| 唐筛21三体临界风险是什么意思| 癔症是什么意思| 脑梗什么症状| 1207是什么星座| 市宣传部长是什么级别| 碳14呼气试验阳性是什么意思| 宁静是什么意思| 蜘蛛喜欢吃什么| 同比增长是什么意思| 非洲说什么语言| 心肌炎吃什么食物最好| 人的脾脏起什么作用| 医院dr检查是什么| 白细胞低说明什么| 脚老抽筋是什么原因| siemens是什么品牌| 男人地盘是什么生肖| cs和cf有什么区别| 吃东西没有味道是什么原因| 土耳其说什么语言| 迪丽热巴什么星座| 甲状腺是什么原因引起的| 转氨酶高吃什么药| 眼睛肿痛什么原因| 老油条什么意思| 初心不改是什么意思| cathy是什么意思| 什么动物的牙齿最多| 砍是什么生肖| 缺氯有什么症状怎么补| 湖南简称什么| 福五行属什么| 丑时属什么| 6月26日什么星座| 口粮是什么意思| 喉咙痛什么原因| 孩子爱咬指甲是什么原因| 拔完牙吃什么药| 烧仙草是什么做的| 瘦马什么意思| 体育总局局长什么级别| 妃子笑是什么茶| 平添的近义词是什么| 肌肉萎缩什么症状| 拉绿屎是什么原因| 尿液弱阳性什么意思| 和田玉对身体有什么好处| 孕早期宫缩是什么感觉| 打嗝是什么意思| 老年人脚肿是什么原因引起的| 巴氏征阳性是什么意思| 宫颈病变是什么| 水泻拉肚子吃什么药| 备孕吃什么好| 身份证最后四位数代表什么| 世界上最大的湖泊是什么湖| 饭后呕吐是什么原因引起的| 梦见被警察抓预示什么| 食欲亢进是什么意思| 西湖醋鱼是什么菜系| 载脂蛋白是什么意思| 支原体肺炎用什么药| 09属什么生肖| 什么铜钱最值钱| 籍贯是指什么| 膝盖窝疼是什么原因| 大黄和芒硝混合外敷有什么作用| 野趣是什么意思| 怀孕一周有什么症状| 提溜是什么意思| 马可以加什么偏旁| 梦见被狗追是什么意思| 64年属什么| 有待提高是什么意思| 膝盖积水是什么原因造成的| 孕期小腿抽筋什么原因| 自由奔放是什么生肖| 数字7五行属什么| 细菌性痢疾吃什么药| 团购什么意思| 浊气是什么意思| 胃癌挂什么科| 红细胞减少是什么原因| 耳麦是什么| n2o是什么气体| 扬州有什么好玩的| 神经性耳鸣吃什么药好| 吃什么会长高| 苏木是什么意思| 六月是什么季节| 属蛇适合佩戴什么饰品| 丰胸吃什么| 恺字五行属什么| ch2o是什么物质| 儿童乳房发育挂什么科| 女生适合养什么狗| 梅长苏是什么电视剧| 后羿和嫦娥是什么关系| 排骨搭配什么菜好吃| 实体店是什么意思| 中线是什么| 医生五行属什么| 头部mra是什么检查| 什么什么什么花| 苍蝇馆子什么意思| cfp是什么证书| 脚扭了挂什么科| 宝宝照蓝光有什么副作用| 乘载和核载是什么意思| 什么化妆品好用哪个牌子的| 高利贷是什么意思| 伏脉常见于什么病| 为什么不建议打水光针| 提篮子是什么意思| 6.24什么星座| 水柔棉是什么面料| 170是什么尺码| 三个龙读什么| 什么饮料不含糖| 做什么检查需要空腹| 吃什么会拉肚子| 蟑螂喜欢吃什么东西| 南红五行属什么| 什么什么的大树| mlb是什么牌子| 咯血是什么意思| alan什么意思| 忘年恋是什么意思| 肠粉为什么叫肠粉| 低钾是什么原因造成的| 10月13号是什么星座| 减肥吃什么药好| 胃糜烂可以吃什么水果| 电磁炉什么牌子好| 入睡难一般是什么原因造成的| 月经咖啡色是什么原因| 映景是什么意思| 失眠吃什么好| 后背疼痛什么原因| 爬山需要准备什么东西| 正切是什么| acer是什么牌子的电脑| 充电宝100wh是什么意思| instagram什么意思| MR医学上是什么意思| 金字旁的有什么字| amber是什么意思| 筒子骨炖什么好吃| 三个句号代表什么意思| 皮肤镜能检查出什么| 日进斗金是什么意思| vmd是什么意思| 常州为什么叫龙城| 三七是什么意思| 硫磺有什么作用| sara是什么意思| 治疗湿疹吃什么药| 神经痛挂什么科| 7月15日是什么节日| 天珠是什么材质| 雪花秀属于什么档次| 倍感欣慰是什么意思| 摆渡人什么意思| 什么叫瑕疵| 憋屎会造成什么后果| 拔完牙吃什么消炎药| 什么去火效果最好| 好雅兴是什么意思| 糖尿病人吃什么好| 安罗替尼适合什么肿瘤| 白佛言是什么意思| 百度Jump to content

阿修罗是什么意思

From Wikiversity
< PHP
百度 P20机模而P20Pro将大到6英寸,取消前置指纹键,同时后置摄像头增至3个。

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 | edit source]

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 | edit source]

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 | edit source]

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 | edit source]

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 | edit source]

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 | edit source]

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 | edit source]

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 | edit source]

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 | edit source]

None available at present.

什么环境唱什么歌原唱 白色泡沫痰是什么原因 保健是什么意思 什么是挂科 腹泻是什么意思
低筋面粉可以用什么代替 备孕喝豆浆有什么好处 8月29日什么星座 鼻腔干燥是什么原因 牙龈经常发炎是什么原因
没什么大不了的 什么也什么造句 反应停是什么药 6.1号是什么星座 胸痹是什么意思
腹腔多发淋巴结是什么意思 早上7点到9点是什么时辰 丘比特是什么意思 龙延香是什么 血小板低是什么意思
吃纳豆有什么好处hcv8jop1ns9r.cn 晨起口干口苦是什么原因hcv9jop1ns3r.cn 中秋节有什么活动hcv9jop0ns3r.cn save是什么意思hcv8jop2ns3r.cn 总胆红素偏高是什么病hcv9jop1ns2r.cn
男人经常熬夜炖什么汤hcv9jop1ns6r.cn nk细胞是什么hcv8jop8ns1r.cn upc码是什么意思hanqikai.com 吃石斛有什么功效hcv8jop2ns6r.cn 没有什么过不去hcv8jop9ns6r.cn
处女座的幸运色是什么zhiyanzhang.com 舌头麻木是什么征兆hcv9jop3ns2r.cn 九点到十点是什么时辰hcv8jop6ns6r.cn 耳鸣吃什么中成药hcv9jop4ns3r.cn 什么叫做原发性高血压hcv8jop3ns4r.cn
脸上为什么会长痣xinjiangjialails.com 吃什么有助于排便hebeidezhi.com 故宫为什么叫紫禁城hcv8jop9ns2r.cn 煎牛排用什么油好hcv8jop9ns6r.cn 海参多少头是什么意思hcv8jop2ns3r.cn
百度