MemoryRefresh!

Array / Storage     Storage



Questions 1 Answers 0%

Pages   0 from 91
Questions   0 from 142

Reset


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 */

Related Pages

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


0% 100%
 
 
0 pages 91 pages
1) Get the json representation of an array





2) Decode the array from string <?php $string = 'a:2:{s:9:"firstname";s:4:"John";s:4:"name";s:5:"Smith";}';







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









Programming

Php
   
Regex
   
MySQL
   
Css
   
jQuery
   
Git
   


References