Could someone please tell me when the decoded contents returns as count = 2 instead of 1?
I presume if the decode array was there then it should be a count of 1 because it's not got multiple array objects inside it.
Example:
// Count 1
Array ( [chat_id] => 414 [inserted] => 1500038898 )
// Count 2
Array (
[0] => Array ([chat_id] => 414 [inserted] => 1500038898)
[1] => Array ([chat_id] => 415 [inserted] => 1500038898)
)
Text file contents:
{"chat_id":414,"inserted":1500038898}
Code:
// Get file contents
$fileContents = json_decode(file_get_contents($file), true);
if($fileContents !== NULL){
// Push decoded contents to temp array
$decoded_data = $fileContents;
print_r(count($decoded_data));
}
Decoded:
Array ( [chat_id] => 414 [inserted] => 1500038898 )