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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:49:43+00:00 2026-06-03T04:49:43+00:00

I have a variable that looks like this: $var = Dropdown\n Value 1\n Value

  • 0

I have a variable that looks like this:

$var = "Dropdown\n
  Value 1\n
  Value 2\n
  Value 3\n";

As you can see it’s basically values broken by line breaks.

What I want to do is get the Option Type, in this case “Dropdown” and store the rest of the values in another string.

So

list($OptionType, $OptionValues) = explode("\n", $var);

The code above is what I tried but this is what the strings came out as:

$OptionType = 'Dropdown'; //Good
$OptionValues = 'Value 1';  // Only got the first value

I want $OptionValues to be like this:
$OptionValues = “Value 1\nValue 2\nValue 3\n”;

How would I do something like that?

The Option Type is always going to be the first part of the string followed by option values each seperated by a linebreak.

It’s organized this way as it comes from user-input and it makes it much easier on the user to handle.

  • 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-03T04:49:44+00:00Added an answer on June 3, 2026 at 4:49 am

    You need to use the third argument of explode(), which sets the limit.

    $var = "Dropdown\n
      Value 1\n
      Value 2\n
      Value 3\n";
    
    list( $foo, $bar ) = explode( "\n", $var, 2 );
    
    echo $bar;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a global variable MyGlobalVar and some code that looks like this: var
I have an int variable that basically looks something like this: 101137111 What I
So I have a JSON variable that looks like this: var peopleList = {
I have written a plugin that looks like this so far: (function($) { var
i have javascript code that looks like this: $('#lnkPopup').click(function() { var id = $(this).attr('rel');
I have a javascript object that looks somthing like this: var obj = {
I have a function that looks exactly like this: function exportSelectedToExcel(id) { var selectedRows
I have a script, which basically looks like this (the part I need help
I have a url that looks like this : http://mysite.com/1/2/Simpson and I want to
I have a method in codeigniter that looks like this, public function category() {

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.