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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:16:41+00:00 2026-05-30T05:16:41+00:00

I have 10 arrays with the following format: This is $data Array ( [0]

  • 0

I have 10 arrays with the following format:

This is $data

Array
(
    [0] => stdClass Object
        (
                [id] => 1
                [name] => Product Name
                [category] => Product category
                [permName] => Product-Name
                [picture] => http://randomdomain.com/1.jpg
                [idUser] => 1,2,3
                [rating] => 120,880,450
                [description] => Review 1, Review 2, Review 3
                [firstName] => Name 1, Name 2, Name 3
                [lastName] => Last 1, Last 2, Last 3
                [userName] => userName 1, Username 2, Username 3
        )
    [1] => stdClass Object
        (
                [id] => 2
                [name] => Product Name 2
                [category] => Product category
                [permName] => Product-Name
                [picture] => http://randomdomain.com/1.jpg
                [idUser] => 1,2,3
                [rating] => 120,880,450
                [description] => Review 1, Review 2, Review 3
                [firstName] => Name 1, Name 2, Name 3
                [lastName] => Last 1, Last 2, Last 3
                [userName] => userName 1, Username 2, Username 3
        )  

)

I wanna turn each arrays idUser, rating, description, firstName, lastName, userName in a nested array. I was thinking of doing something like this:

foreach ($data as $row) {                   
    $firstName = $row->firstName;           
    $firstNames = explode(',', $firstName); 
}

Which turns it into array but how would I then insert it back into the original array in its original spot but as a nested array?

  • 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-05-30T05:16:42+00:00Added an answer on May 30, 2026 at 5:16 am
    <?php
    foreach( $data as $row ) {
        $firstName = $row->firstName;           
        $firstNames = explode(',', $firstName);
        $nested = array();
        foreach( $firstNames as $name ) {
           $nested[] = $name;
        }
        $row->firstName = $nested;
    }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array with the following format: [NSArray arrayWithObjects: [NSArray arrayWithObjects:@number,@name,@date,@about,nil], [NSArray arrayWithObjects:@number,@name,@date,@about,nil],
I have a multi-dimensional array in the following format: [0] = ( 'id' =>
I am new in python.I have data in a 2d- array in the following
I have use following code to display category and there product on click patent
In Java, I have a data in my array like the following 2009.07.25 20:24
I have the following arrays in PHP (okay they are a bit bigger but
I have the following 2 arrays and would like to combine them. I'm more
I have two identical byte arrays in the following segment of code: /// <summary>
I have a project that requires the following. Four arrays will be declared in
I have following array, that I need to operate by hand on bitmaps. const

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.