I receive this JSON string from another site and I cannot modify what received from. The string is receive in $_POST and is :
[
{
\"clientId\":\
I know there is already an answer to this but it may be worth noting that var_dump
outputs Boolean values better it just has worse formatting IMO.
<pre>
<?php
print_r(array(true, false));
var_dump(array(true, false));
?>
</pre>
Results in
Array
(
[0] => 1
[1] =>
)
array(2) {
[0]=>
bool(true)
[1]=>
bool(false)
}
you can use it like this, in JSON
format when you evaluate false
value it will give you blank
, and when you evaluate true
it will give you 1
.
$str = '[{"clientId":"17295c59-4373-655a-1141-994aec1779dc","channel":"\/meta\/connect","connectionType":"long-polling","ext":{"fm.ack":false,"fm.sessionId":"22b0bdcf-4a35-62fc-3764-db4caeece44b"},"id":"5"}]';
$arr = json_decode($str,true);
if($arr[0]['ext']['fm.ack']) // suggested by **mario**
{
echo "true";
}
else {
echo "false";
}
It's a very simple. If you use js to generate and transfer json, pass your variable not in its pure form but: youBoolVar + 0
, then false will be 0, and true 1