Skip to content

Instantly share code, notes, and snippets.

@mikestratton
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikestratton/eb3e7b16a2e193fe31cb to your computer and use it in GitHub Desktop.
Save mikestratton/eb3e7b16a2e193fe31cb to your computer and use it in GitHub Desktop.
identify the data type of a $value using gettype function
<?php
// identify the data type of a $value using gettype function
// http://php.net/manual/en/function.gettype.php
$json = file_get_contents("http://mikestratton.net/temp/bigdatabox/tweetjson_RAW.php");
$t_query = json_decode($json,true);
$name = $t_query ['statuses'][0]['user']['name'];
$screen = $t_query ['statuses'][0]['user']['screen_name'];
$text = $t_query ['statuses'][0]['text'];
$query = $t_query ['search_metadata']['query'];
$j_name = json_decode($name,true);
// test for data type
echo gettype($json), " (json) <br/>";
echo gettype($t_query), " (t_query) <br/>";
echo gettype($name), " (name) <br/>";
echo gettype($screen), " (screen) <br/>";
echo gettype($text), " (text) <br/>";
echo gettype($query), " (query) <br/>";
echo gettype($j_name), " (j_name) <br/><br/>";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment