- BASICS
- Quotes
- Constants
- Control Structures
- Reference
- Number Systems
- VARIABLES
- Definition
- Variable Variable
- Exists
- Type Casting
- OPERATORS
- Aritmetic
- Bitwise
- String
- Comparison
- Logical
- FUNCTION
- Definition
- Anonymous
- Reference
- Variable Arguments
- ARRAY
- Basics
- Operations
- Create
- Search
- Modify
- Sort
-
Storage
- STRING
- String Basics
- String Compare
- String Search
- String Replace
- String Format
- String Regexp
- String Parse
- Formating
- Json
- STREAMS
- File Open
- Read File
- Read Csv
- File Contents
- Context
- Ob_start
- OOP
- Object Instantiation
- Class Constructor
- Interfaces, Abstract
- Resource Visibility
- Class Constants
- Namespaces
- HTTP
- Headers
- File Uploads
- Cookies
- Sessions
Serialize
Generates a storable representation of an array (or object)
/**
* serialize, unserialize()
*
* Storabale representation (string) for an array
*/
$data = ['name'=>'Smith', 'age'=>30];
$encoded = serialize($data);
$decoded = unserialize($encoded);
print_r($encoded); // a:2:{s:4:"name";s:5:"Smith";s:3:"age";i:30;}
print_r($decoded); // [name] => Smith [age] => 30
Json
Encode returns a string containing the json representation.
/**
* Encode anaray, json representation
*/
$A = ['a'=>1, 'b'=>2, 'c'=>3];
$json_encoded = json_encode($A);
$json_decoded = json_decode($json_encoded);
print_r($json_encoded); // {"a":1,"b":2,"c":3}
print_r($json_decoded); // [a=>1, b=>2, c=>3]
Parse ini
Parse a configuration file conf.ini
/**
* parse_ini_file()
*
* inc/config.ini:
*
* url_base = "api.com/RestApi/v1/"
* ssl_verifyhost = 2
* auth_type = "token"
*/
$conf = parse_ini_file(__DIR__ . '/inc/config.ini');
var_dump($conf['ssl_verifyhost'] == 2); // true
var_dump($conf['auth_type'] == 'token'); // true
Last update: 531 days ago