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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:51:49+00:00 2026-06-13T23:51:49+00:00

I am new PHP question and I am trying to create an array from

  • 0

I am new PHP question and I am trying to create an array from the following string of data I have. I haven’t been able to get anything to work yet. Does anyone have any suggestions?

my string:

Acct_Status=active,signup_date=2010-12-27,acct_type=GOLD,profile_range=31-35

I want to dynamically create an array called “My_Data” and have id display something like my following, keeping in mind that my array could return more or less data at different times.

My_Data
(
    [Acct_Status] => active
    [signup_date] => 2010-12-27
    [acct_type] => GOLD
    [profile_range] => 31-35
)

First time working with PHP, would anyone have any suggestions on what I need to do or have a simple solution? I have tried using an explode, doing a for each loop, but either I am way off on the way that I need to do it or I am missing something. I am getting something more along the lines of the below result.

Array ( [0] => Acct_Status=active [1] => signup_date=2010-12-27 [2] => acct_type=GOLD [3] => profile_range=31-35} ) 
  • 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-13T23:51:50+00:00Added an answer on June 13, 2026 at 11:51 pm

    You would need to explode() the string on , and then in a foreach loop, explode() again on the = and assign each to the output array.

    $string = "Acct_Status=active,signup_date=2010-12-27,acct_type=GOLD,profile_range=31-35";
    // Array to hold the final product
    $output = array();
    // Split the key/value pairs on the commas
    $outer = explode(",", $string);
      // Loop over them
    foreach ($outer as $inner) {
      // And split each of the key/value on the =
      // I'm partial to doing multi-assignment with list() in situations like this
      // but you could also assign this to an array and access as $arr[0], $arr[1]
      // for the key/value respectively.
      list($key, $value) = explode("=", $inner);
      // Then assign it to the $output by $key
      $output[$key] = $value;
    }
    
    var_dump($output);
    array(4) {
      ["Acct_Status"]=>
      string(6) "active"
      ["signup_date"]=>
      string(10) "2010-12-27"
      ["acct_type"]=>
      string(4) "GOLD"
      ["profile_range"]=>
      string(5) "31-35"
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to create redirects for /home and /index.php to the site's
New to PHP and MySQL, have heard amazing things about this website from Leo
I am trying to create a PDO class and I get the error: PHP
i'm quite new to php and trying to learn. I have 2 similiar classes.
I'm trying to create a facebook login url using Facebook PHP SDK (v.3.2.0) from
I'm quite new on php and am trying to learn it. My question is
I'm kind of new to backbone coming from knockout.js and I'm trying to get
I'm new to PHP first of all .. My question is once I got
This may be a silly question, but as someone relatively new to PHP, I'm
This sounds like a really simple question, but I am new to PHP. If

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.