Skip to content

Instantly share code, notes, and snippets.

@jlittlejohn
Created May 31, 2013 14:29
Show Gist options
  • Save jlittlejohn/5685356 to your computer and use it in GitHub Desktop.
Save jlittlejohn/5685356 to your computer and use it in GitHub Desktop.
PHP: JSON Encode
<?php
/* Set Content Encoding Header */
header('Content-type: application/json; charset=utf-8');
/* Array of animals*/
$myArray = array(
array('type'=>'cat','name'=>'Alfie','age'=>2),
array('type'=>'dog','name'=>'Bella','age'=>6)
);
/* Encode to JSON */
$jsonString = json_encode($myArray);
echo $jsonString;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment