ExpertRefresh

Array / Storage  

Related Pages

Basics
Operations
Create
Key-value
Search
Modify
Pointer
Sort
Stacks
Randomize
Storage


0.0% 100%
 
 
0 pages 298 questions
1) Decode the array from string <?php $string = 'a:2:{s:9:"firstname";s:4:"John";s:4:"name";s:5:"Smith";}';




2) Get the json representation of an array








serialize() - Generates a storable representation of an array (or object) <?php $data = array( 'firstname' => 'John', 'name' => 'Smith', 'age' => 30, ); echo $string = serialize($data); // a:3:{s:9:"firstname";s:4:"John";s:4:"name";s:5:"Smith";s:3:"age";i:30;} $result = unserialize($string); print_r($result); // Array ( [firstname] => John [name] => Smith [age] => 30 ) json_encode() - Returns a string containing the json representation <?php $arr = array('a' => 1, 'b' => 2, 'c' => 3); echo $json = json_encode($arr); // {"a":1,"b":2,"c":3} $arr2 = json_decode($json); var_dump($arr2); /* object(stdClass)[1] public 'a' => int 1 public 'b' => int 2 public 'c' => int 3 */


References