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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:49:15+00:00 2026-06-16T05:49:15+00:00

I have a variable, let’s call it $var that echoes out something like: 32-Widgets:

  • 0

I have a variable, let’s call it $var that echoes out something like:

32-Widgets: 18,28-Widgets: 24,57-Widgets: 45,44-Widgets: 24,55-Widgets: 45

The variable is created from a combination of a form submission and jQuery Sortables (which is why everything ends up in one variable, not two). The order is very important.

What I’d like to end up with is two variables (can be arrays) that would be:

$newVar1 = 32,18,24,45,24
$newVar2 = Widgets: 18,Widgets: 24,Widgets: 45,Widgets: 24,Widgets: 45

I started by:

$newVars = explode(",",$var);

But I’m at a loss of where to go from there. I’ve tried a variety of statements such as:

foreach ($newVars as $newVar) :
    //Various explode() functions tried here.
endforeach;

If anybody has any idea what I’m missing I would certainly appreciate the help.

Thank you,
Eric

  • 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-16T05:49:16+00:00Added an answer on June 16, 2026 at 5:49 am

    It’s not very pretty, but it’ll do the trick.

    <?php
    
    $str = "32-Widgets: 18,28-Widgets: 24,57-Widgets: 45,44-Widgets: 24,55-Widgets: 45";
    
    $entries = explode(",", $str);
    $parts1 = array();
    $parts2 = array();
    
    foreach ($entries as $e)
    {
        $temp = explode("-", $e);
        $parts1[] = $temp[0];
        $parts2[] = $temp[1];
    }
    
    print_r($parts1);
    print_r($parts2);
    
    ?>
    

    Running example: http://ideone.com/KkL06f

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

Sidebar

Related Questions

So I have this calculator I'm building that accepts user variable inputs like let
So let's say I have variable like this one: $q = DB::select('id')->from('reports')->where('field', '=', 'value');;
I have a variable that is increasing let's say from 0 to 99. Then
I need to have a variable that only one function can write (let's call
Let's say I have a variable like this: var a = this.property || this.parent.anotherProperty;
Let's say that i have a variable questionId which is an integer, and i
Let's say I have a variable that will always be a string. Now take
Let's say I have a variable t that's set to this: datetime.datetime(2009, 7, 10,
In my Cocoa/iOS application I have a static double variable (let's call it foo
I have an variable that I need to alter inside the template. Let's say

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.