首页 / PHP / PHP: Learning Notes
PHP: Learning Notes
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了PHP: Learning Notes,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3102字,纯文字阅读大概需要5分钟。
内容图文
php basics
in PHP, variables are defined as $_alphanum
variables should always prefixed a $
variables defined/assigned outside of a function cannot be used inside a function, unless declared inside function with keyword global $var. Also can be used as $GLOBALS[‘var‘] for in/out.
echo variables: (all of the 3 examples are okay)
echo $x echo "x is equal to $x" echo "x is equal to " . $x
comments can be:
# comments // comments /* comments */
the static keyword inside function keeps the variable change everytime calls the function.
----
php functions
echo: what echo echoes is pure-html, can be tagged htmls. echo strings concat using ., echo variables can do math ops. echo multiple elements separated by ,
print: print only accept one element, returns 1, slower
---
php types
- String
- Integer
- Float (floating point numbers - also called double)
- Boolean
- Array
- Object
- NULL
- Resource
var_dump($var) function dumps a var together with its type
bool: false true
create arrays by array() constructor. $x= array("a","b","c")
object are instances of class, class can be defined by:
class Car { function Car() { $this->model = "VW"; } }
instantialize it to object by new:
$herbie = new Car();
any var created without init is as null.
resource type: relating to db calls
---
php string manipulating
strlen(): counts to last ‘\0‘
str_word_count(): counts words
strrev(), reverse a string str->rts
strpos(str, pattern), returns start of pattern idx in str
str_replace(patt, rep, str) returns str‘s all pattern replaced by rep
complete list of string funcs: here
----
php constants
define(name,value[,opt-case-sensitive])
----
php arith
===, ==, !=, !==, ++, --, and(&&), or(||), xor, !,
.=: str concat
---
php cond
if, switch($var)->case:->break->default:
---
php function
<?php function func($val=40) //func with opt parm val, defaults to 40{} func(); //call it ?>
---
php array
count($arr) returns count of array elems
array can also be created in associative way:
$age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43"); foreach($ageas$x => $x_value) { echo "Key=" . $x . ", Value=" . $x_value; echo "<br>"; }
array can be called recursively to create multi-level array
complete array intro is here.
sorting an array in different ways: sort, rsort, asort, ksort, arsort, krsort.. indexed/associative arrays are sorted using different functions
---
php globals
- $GLOBALS
- $_SERVER
- $_REQUEST
- $_POST
- $_GET
- $_FILES
- $_ENV
- $_COOKIE
- $_SESSION
$GLOBALS is introd before
$_SERVER[‘HTTP_USER_AGENT‘] returns user-agent field of the incoming request. other fields can be PHP_SELF, SERVER_NAME, HTTP_HOST, SCRIPT_NAME, REQUEST_METHOD.. more to look at here.
$_REQUEST[‘varname‘] is used to collect the value of the input field from a form.
$_POST[‘varname‘] is used to collect the value of a post http request with key=varname
$_GET[‘varname‘] is used to collect the value of a request which has uri: domain.com/page.html?varname=value
post key-values may be embedded in ssl/tls, so its sneaker than get option
原文:http://www.cnblogs.com/sansna/p/7891754.html
内容总结
以上是互联网集市为您收集整理的PHP: Learning Notes全部内容,希望文章能够帮你解决PHP: Learning Notes所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。