Use as
$availability = $decode["availability"];
If you use
$availability = $decode[availability];
It will raise a notice as
Notice: Use of undefined constant availability - assumed 'availability'
However your code is correct is should display the value with the above notice unless the $json
string is not the one you have added.
Your code
<?php
$arr = array('name' => peter, 'availability' => available);
$json = json_encode($arr);
$decode = json_decode($json, true);
$availability = $json_decode[availability];
print_r($json);
echo $availability;
?>
Now this is what you are doing
$decode = json_decode($json, true);
$availability = $json_decode[availability];
You are using a different array name $json_decode
instead of $decode
So the correct way is
$arr = array('name' => 'peter', 'availability' => 'available');
$json = json_encode($arr);
$decode = json_decode($json, true);
$availability = $decode['availability']; //print_r($json);
echo $availability;