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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:44:14+00:00 2026-06-13T23:44:14+00:00

I am using array functions to convert my pipe delimited string to an associative

  • 0

I am using array functions to convert my pipe delimited string to an associative array.

$piper = "|k=f|p=t|e=r|t=m|";

$piper = explode("|",$piper);

$piper = array_filter($piper);

function splitter(&$value,$key) {

    $splitted = explode("=",$value);
    $key = $splitted[0];
    $value = $splitted[1];

}

array_walk($piper, 'splitter');

var_dump($piper);

this gives me

array (size=4)
  1 => string 'f' (length=1)
  2 => string 't' (length=1)
  3 => string 'r' (length=1)
  4 => string 'm' (length=1)

where i want:

array (size=4)
  "k" => string 'f' (length=1)
  "p" => string 't' (length=1)
  "e" => string 'r' (length=1)
  "t" => string 'm' (length=1)

but the keys are unaltered. Is there any array function with which i can loop over an array and change keys and values as well?

  • 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-13T23:44:16+00:00Added an answer on June 13, 2026 at 11:44 pm

    It’s said in the documentation of array_walk (describing the callback function):

    Only the values of the array may potentially be changed; its structure
    cannot be altered, i.e., the programmer cannot add, unset or reorder
    elements. If the callback does not respect this requirement, the
    behavior of this function is undefined, and unpredictable.

    That means you cannot use array_walk to alter the keys of iterated array. You can, however, create a new array with it:

    $result = array();
    array_walk($piper, function (&$value,$key) use (&$result) {
        $splitted = explode("=",$value);
        $result[ $splitted[0] ] = $splitted[1];
    });
    var_dump($result);
    

    Still, I think if it were me, I’d use regex here (instead of “exploding the exploded”):

    $piper = "|k=f|p=t|e=r|t=m|";
    preg_match_all('#([^=|]*)=([^|]*)#', $piper, $matches, PREG_PATTERN_ORDER);
    $piper = array_combine($matches[1], $matches[2]);
    var_dump($piper);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How would I convert the following to a VB.NET predicate using Array.Find? Private Function
I'm using an array of images with next/previous functions to navigate through the images.
I get an array using the function preg_match_all. The code is as it is:
I need an array of 820 zeros for using with a mathematical function. In
I want to reverse a 2d array of type char using std::reverse() function in
I am trying to convert a PIL image into an array using NumPy. I
Hello I'm trying to convert the following functions to a VBO based function for
I'm trying to convert a floating point to byte array/stream using javascript. My javascript
I'm using OpenGL and I need to pass to a function array of bytes.
I have created an ienumerable of lambda functions using this function static IEnumerable<Func<int>> MakeEnumerator(int[]

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.