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: 432 days ago