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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:02:29+00:00 2026-06-13T09:02:29+00:00

I have a flat array of pipe-delimited strings: Array ( [0] => style1|000000 [1]

  • 0

I have a flat array of pipe-delimited strings:

Array
(
    [0] => style1|000000
    [1] => style2|ff6600
)

I iterate the data like this:

foreach ($styles as $key => $value) {
    $sort_values[] = explode('|', $value);
}

print_r($sort_values) shows:

Array
(
    [0] => Array
        (
            [0] => style1
            [1] => 000000
        )
    [1] => Array
        (
            [0] => style2
            [1] => ff6600
        )
)

I would actually like a transposed structure with associative first level keys:

Array
(
    [styles] => Array
        (
            [0] => style1
            [1] => style2
        )
    [links] => Array
        (
            [0] => 000000
            [1] => ff6600
        )
)
  • 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-13T09:02:31+00:00Added an answer on June 13, 2026 at 9:02 am

    Assuming your input array looks like

    array('style1|000000','style2|ff6600', 'style3|22ff22')
    

    You need a little more logic in your loop.

    // Initialize output array with an empty styles subarray and a links subarray
    $out = array('styles'=>array(), 'links'=>array());
    foreach ($styles as $key=>$value) {
       // Loop over and split on the |
       list($style, $link) = explode("|", $value);
       // And append the two resultant values to their respective subarrays via []
       $out['styles'][] = $style;
       $out['links'][] = $link;
    
       // list() is a useful construct for producing readable results with small arrays,
       // but I could also have used an array to receive the 
       // results of explode()
       // $split = explode("|", $value);
       // $out['styles'][] = $split[0];
       // $out['links'][] = $split[1];
    
    }
    print_r($out);
    
    // Prints:
    Array
    (
        [styles] => Array
            (
                [0] => style1
                [1] => style2
                [2] => style3
            )
    
        [links] => Array
            (
                [0] => 000000
                [1] => ff6600
                [2] => 22ff22
            )
    
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a flat file that is pipe delimited and an database table. I
I have an array that is read from a flat file that looks like
I have a form which is posting an array which looks like this: Array
I have a collection of keys in this massive flat single array I would
I have an array like this: [ [ 'key1' => 'hello im a text',
I have a windows mobile 5.0 application (smartphone) that contains a flat data file
I have simple SSIS package which reads data from flat file and insert into
I have an OLE DB Data source and a Flat File Destination in the
I have simple SSIS package where I import data from flat file into SQL
I have a tab delimited file on a shared path. I've setup that flat

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.