Need double quotes in $val field
===

We are creating a file such that when we execute the file we push an array into a new PHP file . 
We are able to print the array details in new PHP file but we are not able to get the double quotes for the $val fields . 

Code is as follows

    <?php
    include_once("../dc/dcCommonLib.php");
    include_once("../dc/persistence/UserData.php");
    require_once("../../lib/include/connect.inc.php");
    
    $_SESSION["survey"] = "BestBuyAug2012";
    $idLink = dbconnect($_SESSION["survey"]);
    $surveyWidget = rendererSurveyLoadHandler();
    setDataToSession("surveywidget",$surveyWidget);
    $userData = &UserData::getInstance();
    $userData->setSurvey($surveyWidget);
    saveFkidsToOidToFkidMappingArray($userData->OidToFkidMapping);
    
    // prepare demo array
    prepareItemArray($userData->OidToFkidMapping["Demographic"]["Q"],$demo,"b");
    
    // prepare item array
    prepareItemArray($userData->OidToFkidMapping["Default"]["Q"],$item,"i");
    prepareItemArray($userData->OidToFkidMapping["Default"]["M"],$item,"i");
    
    // prepare comment array
    prepareCommentArray($userData->OidToFkidMapping["Comment"]["C"],$comment);
    
    
    if(!function_exists('file_put_contents')) 
    {
        function file_put_contents($filename, $data,$type, $file_append = false)
    	 {
        		  $fp = fopen($filename, (!$file_append ? 'w+' : 'a+'));
           	 if(!$fp)
    			 {
             			 trigger_error('file_put_contents cannot write in file.', E_USER_ERROR);
             			 return;
           		 }
    
        			if($type)
    			{
    
        				$count = count($data);
        				$i = 1;
        				//loop through your type array and append comma , to each except last
        				foreach($data as $key=>$val)
    				 {
    
    					if($i < $count)
    
             				 $data[$key] .= ',';
                   			$i++;
    				}
    
       			 //run same preg_replace as before
       			 $data2 = preg_replace('/[\[\]]/','"',print_r($data,TRUE));
         
        			//write to file 
       			 fputs($fp, "$" . $type . " = " . print_r($data2,TRUE));  
          
     			 }
         			 else 
    			{
          				fputs($fp, print_r($data, TRUE));
    	
         			 }
         			 fclose($fp);
       		 }
    
    
    }
    print("Strart writting ...................");
    file_put_contents("Test.php", $file,"",true);
    file_put_contents("Test.php", "<?php\n","",true);
    file_put_contents("Test.php", $item,"itemFkids",true);
    file_put_contents("Test.php", $demo,"demoFkids",true);
    file_put_contents("Test.php", $comment,"commentFkids",true);
    file_put_contents("Test.php", "?>","",true);
    
    print("written ...");
    
    function prepareItemArray($userDataArray, &$item, $itemStr) {
    	if(is_array($userDataArray)) {
    		foreach($userDataArray as $questId=>$respGrp) {
    			$selectionGrp=array_unique($respGrp);
    			if(count($selectionGrp)==1) {
    				$respGrpId=key($respGrp);
    				$respId = key($respGrp[$respGrpId]);
    				$item[$questId."_".key($respGrp)]=$itemStr.$respGrp[$respGrpId][$respId];			
    			}else {
    				foreach ($respGrp as $respGrpId=>$resp) {
    					$respGrp[$respGrpId]=$itemStr.$resp;
    				}
    				$item[$questId."_".key($respGrp)]=$respGrp;
    			}
    		}
    	}	
    }
    
    function prepareCommentArray($userDataArray, &$item) {
    	if(is_array($userDataArray)) {
    		foreach($userDataArray as $questId=>$respGrp) {
    			$selectionGrp=array_unique($respGrp);
    			if(count($selectionGrp)==1) {
    				$respGrpId=key($respGrp);				
    				$item[$questId."_".key($respGrp)]=$respGrp[$respGrpId]["fk_id"];			
    			}
    		}
    	}	
    }
    
    ?>

the array that we get in Test.php is 

    <?php
    $itemFkids = Array
    (
        "203_19" => i27,//need double qoutes for all the $val fields
        "207_22" => i28,//need double qoutes for all the $val fields
        "357_22" => i99,//need double qoutes for all the $val fields
        "370_70" => i104,//need double qoutes for all the $val fields
        "377_72" => i105,//need double qoutes for all the $val fields
    )
    $demoFkids = Array
    (
        "129_2" => b1//need double qoutes for all the $val fields
    )
    $commentFkids = Array
    (
        "373_375" => 1,//need double qoutes for all the $val fields
        "380_382" => 2//need double qoutes for all the $val fields
    )
    ?>

Any help is appreciated . 