Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8283873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:53:53+00:00 2026-06-08T10:53:53+00:00

When I insert an array into a new php file I do not get

  • 0

When I insert an array into a new php file I do not get a semicolon at the end of each array . I need to get a semicolon at the end of each array.

File1

  <?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)//code which is concerned with the execution of array
            {

                    $count = count($data);
                    $i = 1;
                    //loop through your type array and append comma and double qoutes , 
                    foreach($data as $key=>$val)
                 {

                    if($i = $count)

                        $data[$key] = '"'.$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("staticSurveyDataFileTest.php", $file,"",true);
file_put_contents("staticSurveyDataFileTest.php", "<?php\n","",true);
file_put_contents("staticSurveyDataFileTest.php", $item,"itemFkids",true);
file_put_contents("staticSurveyDataFileTest.php", $demo,"demoFkids",true);
file_put_contents("staticSurveyDataFileTest.php", $comment,"commentFkids",true);
file_put_contents("staticSurveyDataFileTest.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"];            
            }
        }
    }   
}

?>

Output which I get in File2 is(As mentioned earlier I need to have a semicolon at the end of each array)

<?php
$itemFkids = Array
(
    "203_19" => "i27",
    "207_22" => "i28",
    "357_22" => "i99",
    "370_70" => "i104",
    "377_72" => "i105",
    "140_8" => "i1",
    "141_8" => "i2",
    "142_8" => "i3",
    "143_8" => "i4",
    "144_8" => "i5",

)//need a semicolon here
$demoFkids = Array
(
    "129_2" => "b1",
)//need a semicolon here
$commentFkids = Array
(
    "373_375" => "1",
    "380_382" => "2",
)//need a semicolon here
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T10:53:54+00:00Added an answer on June 8, 2026 at 10:53 am

    I haven’t done this before, but couldn’t you just add another couple file_put_contents? How does that turn out?

    file_put_contents("staticSurveyDataFileTest.php", $file,"",true);
    file_put_contents("staticSurveyDataFileTest.php", "<?php\n","",true);
    file_put_contents("staticSurveyDataFileTest.php", $item,"itemFkids",true);
    file_put_contents("staticSurveyDataFileTest.php", ";","",true);
    file_put_contents("staticSurveyDataFileTest.php", $demo,"demoFkids",true);
    file_put_contents("staticSurveyDataFileTest.php", ";","",true);
    file_put_contents("staticSurveyDataFileTest.php", $comment,"commentFkids",true);
    file_put_contents("staticSurveyDataFileTest.php", ";\n?>","",true);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to Java. I want to create Java Array and insert data into
I am very new to mysql and php. I need to put an array
im trying to insert an array values into the file using foreach.. and if
Based on this question How to insert array into mysql using PDO and bindParam?
I'd like to use a foreach loop to insert a _POST associative array into
I'm using this line of code to insert a value from an array into
I'm trying to insert into an array at a certain point: $hi = test;
How would one insert an array full of smtp email addresses into an AD
I have this array that I am needing to insert into the database. My
I have a byte array highlighted below, how do I insert it into a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.