Skip to content

Instantly share code, notes, and snippets.

@sineld
Created April 28, 2012 20:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sineld/2521745 to your computer and use it in GitHub Desktop.
Save sineld/2521745 to your computer and use it in GitHub Desktop.
Json and php
<?php
$dizi = array('koca' => array('isim' => 'sinan', 'yas' => 31), 'es' => array('isim' => 'bilge', 'yas' => 22));
echo 'Php: ';
var_dump($dizi).'<br>';
$d = json_encode($dizi);
echo 'Json (encoded): ';
var_dump($d). '<br>';
echo 'Json (decoded): ';
var_dump(json_decode($d));
$d = json_decode(json_encode($dizi));
echo $d->es->isim;
?>
Php:
array
'koca' =>
array
'isim' => string 'sinan' (length=5)
'yas' => int 31
'es' =>
array
'isim' => string 'bilge' (length=5)
'yas' => int 22
Json (encoded):
string '{"koca":{"isim":"sinan","yas":31},"es":{"isim":"bilge","yas":22}}' (length=67)
Json (decoded):
object(stdClass)[1]
public 'koca' =>
object(stdClass)[2]
public 'isim' => string 'sinan' (length=5)
public 'yas' => int 31
public 'es' =>
object(stdClass)[3]
public 'isim' => string 'bilge' (length=5)
public 'yas' => int 22
bilge
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment