Skip to content

Instantly share code, notes, and snippets.

@oakwoodgates
Last active November 10, 2018 05:06
Show Gist options
  • Save oakwoodgates/fbcbb4cc6df68789a0171afc845fd43c to your computer and use it in GitHub Desktop.
Save oakwoodgates/fbcbb4cc6df68789a0171afc845fd43c to your computer and use it in GitHub Desktop.
<?php
$string = '{"emptyString":"","stringSpace":" ","zeroInteger":0,"zeroString":"0","nullVal":null,"falseVal":false,"emptyArray":[]}';
$array = json_decode( $string, true );
echo $string;
echo'<pre>';print_r( $array );echo'</pre>';
echo '<table>';
echo '
<tr>
<th></th>
<th>!empty</th>
<th>isset</th>
<th>!null</th>
<th>true</th>
</tr>';
foreach ( $array as $key => $value ) {
echo '<tr><td>'.$key.': </td><td>';
echo ( !empty( $value ) ) ? 'true' : 'false'; echo '</td><td>';
echo ( isset( $value ) ) ? 'true' : 'false'; echo '</td><td>';
echo ( !is_null( $value ) ) ? 'true' : 'false'; echo '</td><td>';
echo ( $value ) ? 'true' : 'false';
echo '</td></tr>';
}
echo '<tr><td>iDontExist: </td><td>';
echo ( !empty( $array['iDontExist'] ) ) ? 'true' : 'false'; echo '</td><td>';
echo ( isset( $array['iDontExist'] ) ) ? 'true' : 'false'; echo '</td><td>';
/* echo ( !is_null( $array['iDontExist'] ) ) ? 'true' :false; */
echo 'error'; echo '</td><td>';
/* echo ( $array['iDontExist'] ) ? 'true' :false; */
echo 'error'; echo '</td></tr>';
echo '<tr><td>_</td></tr>';
echo '</table>';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment