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 7647445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:27:44+00:00 2026-05-31T10:27:44+00:00

I want to save a PHP associative array from a PHP varible to a

  • 0

I want to save a PHP associative array from a PHP varible to a MYSQL database, then later access the stored value (within the MYSQL database) and use it within PHP as an associative array.

$arr = array("abc"=>"ss","aaa"=>"ddd");

now i want to save

array("abc"=>"ss","aaa"=>"ddd");

to the database and again want to retrive it and assign it to variable.

I tried to use the serialize function, but it only saved the word “Array” into database.

  • 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-31T10:27:45+00:00Added an answer on May 31, 2026 at 10:27 am

    One way to do this is to serialize it into a string before insert, and then deserialize it into array after fetching. There are different ways to do that, but if your arrays are simple, JSON is an acceptable serialization format.

    You could json_encode on the way in:

    $str = json_encode($arr);
    // Insert $str into db
    

    Then json_decode later:

    // Got $str from db
    $arr = json_decode($str);
    

    Another method is serialize:

    $str = serialize($arr);
    // Insert $str into db
    

    And unserialize:

    // Got $str from db
    $arr = unserialize($str);
    

    This will allow more possibilities for what you can serialize than json_encode and json_decode, but it will be harder to inspect the database manually to see what’s in there.

    So both methods have advantages and disadvantages. There are other serialization/marshal formats out there too.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to recognize (with php, mysql) and save which blog entries a user
I have a few php pages that might want to access the database and
I want to save the date and time from PHP to SQL. Here is
I want to save data in Hindi Unicode format in my database using PHP.
i want to save the Symbols , and — in a MySQL Database with
I'm getting an array of strings from a JSON object. I want to save
i want to save an .XML file that i create with php dom, but
i've made this php function to resize picture , and i want to save
When a user logs in I want to save their IP in the database.
I want to save data into a server. This is my simple php code:

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.