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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T11:47:00+00:00 2026-06-02T11:47:00+00:00

I am trying to write a function in PHP, but being a novice I

  • 0

I am trying to write a function in PHP, but being a novice I am finding it a bit difficult to do so. I have an array which looks like

[{"x":"12345","y":"john"},{"x":"12345","y":"stars"}]

The function which I am writing is

function getCSV($x)
{

    // Now I want to pass the $x which in the above array is 12345 and get "john,stars"  as output
}

Are there any methods available in PHP that can do this, or what would be the best approach to get it?

  • 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-02T11:47:02+00:00Added an answer on June 2, 2026 at 11:47 am

    That looks like a json to me

    [{"x":"12345","y":"john"},{"uid1":"12345","uid2":"stars"}]
    
    
    function getCSV($x)
    {
        $arr = json_decode($x);
        echo $arr[0]->y . ', ' . $arr[1]->uid2;
    }
    

    This looks horrible, but withouth further explanation is the only thing that works

    EDIT – after your edit

    function getCSV($x)
    {
        $arr = json_decode($x);
        $y = array();
        foreach($arr as $obj){
            $y[] = $obj->y;
        }
        return implode(',', $y);
    }
    

    here is a working pad http://codepad.org/HzttdmjW

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

Sidebar

Related Questions

I am new to php and trying to write a login function. Bit stuck
I am trying to write a PHP function which gets the sum of values
I am trying to write a php function to stop MySQL injection attempts. What
I'm trying to write a php function that gets all the basic food data.
I am trying to write a function that includes a file named header.php in
I am trying write a function that generates simulated data but if the simulated
Can PHP dissect its own syntax? For example, I'd like to write a function
I'm trying to write a sitemap.php which acts differently depending on who is looking.
I'm trying to write a custom session persister in PHP. But for some reason
I am trying write a PHP function that returns a random string of a

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.