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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:19:37+00:00 2026-05-30T18:19:37+00:00

I am getting started with php, and I was wondering if it was possible

  • 0

I am getting started with php, and I was wondering if it was possible to explode a string into an array with named variables. The set up is that I have some data I am reading in from a text file, and I want to break it up into rows first and then break it up into individual pieces of data.

 Data1  |  Data2  |  Data3  |
 ----------------------------
|   x   |    y    |    z    |
|   p   |    q    |    r    |

So I am trying to end up with something like:

data {
   row1 {
       data1: x
       data2: y
       data3: z
   row2 {
       data1: p
       data2: q
       data3: r
   }
}

and I would like be able to access the data using the names of the variables if possible:

$r1d1 = data[row1]['data1'];

  • 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-30T18:19:38+00:00Added an answer on May 30, 2026 at 6:19 pm

    If you want to explode a string into an associative array, you can use the list function.

    // Initialize data_list
    $data_list = array();
    
    // Remove delimiter at start and end of string
    $string = trim('|   x   |    y    |    z    |', '|');
    
    $data = array();
    list($data['data1'],$data['data2'],$data['data3']) = explode('|',$string);
    
    $data_list[] = $data;
    

    You would want to have it wrapped into a foreach loop to process each line of the file. In the end the $data_list would contain all the data.

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

Sidebar

Related Questions

Possible Duplicate: Getting Started with PHP Extension-Development Has anyone got some resources on how
I'm getting started with a side project that will be developed using PHP and
I'm getting started unit testing my PHP application with PHPUnit. I understand that it's
Getting started in PHP, but even with a Hello world I'm running into problems
I'm just getting started with soap communication through php. I have access to a
Just getting started using MVC in ASP.NET, I'm going to have it so users
I am getting started with OO PHP, and after reviewing a variety of classes
I'm just getting started in CakePHP, and am running into trouble limiting retrieved results
I have written web apps with JSP in the past. Now, I'm getting started
I was wondering if anyone has a preferred set of plugins that they use

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.