PHP Basics
In PHP, variables is 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 Ke Yword Global $var. Also can used as $GLOBALS [' var '] for in/out.
echo variables: (All of the 3 examples is okay)
Echo $x Echo $x"echo$x
Comments can be:
# 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 is instances of class, class can 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 the last ' + '
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//func with opt parm val, defaultsto +// call It?>
---
PHP array
COUNT ($arr) returns count of array Elems
Array can also is created in associative:
$age Array ("Peter" and "+", "Ben" = "Panax Notoginseng", "Joe" and "a"); foreach ($ageas$x$x _value) { echo$x$x _value ; Echo "<br>";}
Array can called recursively to create multi-level array
Complete array intro are here.
Sorting an arrays in different ways:sort, Rsort, Asort, Ksort, Arsort, Krsort. Indexed/associative arrays is 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 on 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' are used to collect the value of a request which have uri:domain.com/page.html? varname=value
Post key-values embedded in SSL/TLS, so it sneaker than get option
Php:learning Notes