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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T23:40:23+00:00 2026-06-06T23:40:23+00:00

I am working with a web service that returns JSON data, which, when I

  • 0

I am working with a web service that returns JSON data, which, when I decode with PHP’s json_decode function, gives me an array like the following:

Array
(
 [0] => eBook
 [1] => 27
 [2] => Trade Paperback
 [3] => 24
 [4] => Hardcover
 [5] => 4
)

Is there a PHP function that will take this array and combine it into an associative array where every other element is a key and the following element is its value? What I want to come up with is the following:

Array
(
 [eBook] => 27
 [Trade Paperback] => 24
 [Hardcover] => 4
)
  • 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-06T23:40:24+00:00Added an answer on June 6, 2026 at 11:40 pm

    Your own solution is clearer for sure, but this one-liner, made of PHP functions only, does the same job:

    $output = call_user_func_array('array_combine', call_user_func_array('array_map', array_merge(array(null), array_chunk($input, 2))));
    

    Your question was “is there a PHP function…”. The answer is no, but for a combination thereof it is yes.

    The tricky part here is the transposition of the chunked array, which is achieved by calling array_map with null as the first argument (see the manual where it says “an interesting use of this function…”)

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

Sidebar

Related Questions

I created a web service which returns JSON or so I think. The data
I'm working with a web service that will give me values like: var text
I'm working on a Rails-based web service that provides data about various sports team
I am working on a web service the needs to return JSON data. I
I'm working on creating a WCF web service that communicates via JSON. I got
I am working on an app that talk to Rest web service. The JSon
I am working on an iPad app that is fed data via web service
I have web service urls that were working fine and are now returning the
Hi i am working on web service application in android.i need a class that
I am working on a Java Web Application that exposes a web service. This

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.