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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:48:46+00:00 2026-06-01T16:48:46+00:00

I have a cookie which I’m trying to split. The cookie is in this

  • 0

I have a cookie which I’m trying to split. The cookie is in this format:

key = val1,val2,val3 (where each value is separated by commas)

is there a way for me to split this in a loop so that I can directly access val3?

I’ve tried using the explode() function with no success.

for ($i = 0; $i < count($_COOKIE); $i++)
{
    $ind = key($_COOKIE);
    $data = $_COOKIE[$ind];

    //I try and slit the cookie here
    $cookie_temp = explode(",",$_COOKIE[$ind]);

    //Here is where I wanted to display Val3 from the cookie
    print $cookie_temp[2];

    next($_COOKIE);
} 

my code works fine but I then end up with all my Val3 in a large array. For example, my val3’s are numbers and they get put in an array. Can I split this even further?

  • 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-01T16:48:47+00:00Added an answer on June 1, 2026 at 4:48 pm

    Assuming you are looping because you have multiple comma-separated cookie key/value groups, use a foreach() instead and with list() you can retrieve the third value with a direct assignment.

    foreach ($_COOKIE as $key=>$value) {
      list($v1, $v2, $v3) = explode("," $value);
      echo $v3;
    }
    

    If you have only one cookie value to access, there is no need for the loop, and you can directly call explode(",", $_COOKIE['key'])

    PHP 5.4 allows array dereferencing, whereby you can directly access the array element off of the explode() call, but this won’t work in earlier PHP versions.

    echo explode(",", $_COOKIE['key'])[2];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a cookie which stores info in an array. This is for a
I have been trying like this - // ================ // = set a Cookie
I have a cookie, called 'plan' which contains a string value representing a RaphaelJS
I have a cookie checker function, which storage a value variable in the var
I have a URI here in which a simple document.cookie query through the console
I have one application which uses the standard .NET forms authentication cookie, now I
I have a cookie set as yab_uploadmode and it has numeric value ranging from
I have many cookie-cutter spring beans and don't want to explicitly define each one
I have the following code that sets a cookie: string locale = ((DropDownList)this.LoginUser.FindControl(locale)).SelectedValue; HttpCookie
I have a cookie which is set when a user accesses the page /auth/

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.