Help me understand what you mean it is outputting the following?
<?php
$myArray = array('plaintext' => 'This is an example CV.', 'filename' => '1345730220.doc');
$jsonString = json_encode($myArray);
$decodedArray = json_decode($jsonString, true); // Note: I pass true for the $assoc optional parameter
var_dump($myArray, $decodedArray); // Should be nearly identical
echo $decodedArray['plaintext'];
?>
If you want an associative array after decoding the json_encode output, then yes. Otherwise, you end up with an object and have to access your values like so: $decodedArray->plaintext and $decodedArray->filename versus, when using true in the optional parameter, you can use it as $decodedArray[‘plaintext’] and $decodedArray[‘filename’]
Instead of using json_encode()/json_decode(), use serialize()/unserialize(). The latter allows you to do things like transfer PHP objects intact across hosts while JSON is more limited. If you are transferring data from a database, I recommend doing:
For the destination. That’s the fastest, easiest way to get data to cross from one PHP host to another on a temporary basis (e.g. a data migration export/import script set for a redesigned web app). You wouldn’t want to do this sort of thing for anything other than a quick-n-dirty script that will be used just once or twice - otherwise you’ll create a maintenance nightmare in short order.