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

  • SEARCH
  • Home
  • 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 3396976
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:28:22+00:00 2026-05-18T04:28:22+00:00

I am trying to pass my array of lat and lng to my PHP

  • 0

I am trying to pass my array of lat and lng to my PHP script so that the script can save it to an .txt file.

i manage to serialize my array and pass it to the php script… and on the php side, i manage to unserialize it. However, when i write the array to the file, the file only show as “array array array” … and not the value… suppose to be “(1.3567, 103.124252) (1.3543, 103.436435)”.

Below is my sample code (to serialize):

function serialize(mixed_value) 
   { 
    var _getType = function( inp ) {
    var type = typeof inp, match;
    var key;
    if (type == 'object' && !inp) {
     return 'null';
    }
    if (type == "object") {
     if (!inp.constructor) {
      return 'object';
     }
     var cons = inp.constructor.toString();
     match = cons.match(/(\w+)\(/);
     if (match) {
      cons = match[1].toLowerCase();
     }
     var types = ["boolean", "number", "string", "array"];
     for (key in types) {
      if (cons == types[key]) {
       type = types[key];
       break;
      }
     }
    }
    return type;
   };
   var type = _getType(mixed_value);
   var val, ktype = '';

   switch (type) {
    case "function": 
     val = ""; 
     break;
    case "undefined":
     val = "N";
     break;
    case "boolean":
     val = "b:" + (mixed_value ? "1" : "0");
     break;
    case "number":
     val = (Math.round(mixed_value) == mixed_value ? "i" : "d") + ":" + mixed_value;
     break;
    case "string":
     val = "s:" + mixed_value.length + ":\"" + mixed_value + "\"";
     break;
    case "array":
    case "object":
     val = "a";
     var count = 0;
     var vals = "";
     var okey;
     var key;
     for (key in mixed_value) {
      ktype = _getType(mixed_value[key]);
      if (ktype == "function") { 
       continue; 
      }

      okey = (key.match(/^[0-9]+$/) ? parseInt(key, 10) : key);
      vals += serialize(okey) +
        serialize(mixed_value[key]);
      count++;
     }
     val += ":" + count + ":{" + vals + "}";
     break;
   }
   if (type != "object" && type != "array") {
     val += ";";
    }
   return val;
   }

PHP (to unserialize and paste to file):

$data = $_POST['y'];

$arr = unserialize($data); 

$fp=fopen("route.txt","w+");
foreach($arr as $key => $value){
fwrite($fp,$value."\t");
}

THANKS FOR ALL YOUR HELP! 😀

  • 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-05-18T04:28:23+00:00Added an answer on May 18, 2026 at 4:28 am
    1. Reinvent wheels much? 🙂 There’s already JSON for expressly this purpose, and there are a ton of libraries out there for en- and decoding JSON in just about any language. PHP comes with json_decode.
    2. When writing to the file, $value itself is an array. When an array is cast to a string (as is necessary for outputting it), it’ll be cast to the string “Array”. Use join(',', $value) to output all values of the array separated by commas.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

im trying to pass an array of data to a PHP script using Jquery's
I have an array in Javascript that i am trying to pass to php.
I'm trying to pass an array like this using jQuery, but the PHP script
I am trying to pass a array that contains keys and values. The keys
I am currently trying to pass an array that I have created in Javascript
i'm trying to pass a javascript array to a php controller ( i'm using
Im trying to pass an array that I already found by a query into
I am trying to pass an array to a ruby script from a command
Am trying to pass an array of values from PHP function to Javascript. Not
I am trying to pass an integer array to a baseadapter, such that A.class

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.