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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:36:13+00:00 2026-05-26T11:36:13+00:00

I have an stdClass Object ( [cart_item_id] => 319299 [cart_id] => 1 [nid] =>

  • 0

I have an

stdClass Object ( [cart_item_id] => 319299 
[cart_id] => 1 
[nid] => 2140 
[qty] => 15 
[changed] => 1319485739 
[data] => Array ( 
     [gift_description] => ghgfdhfghfh 
     [gift_email] => hgffghhg@gjfdhjk.com
     [gift_sender] => gfdhgfdhgfdhgf 
     [gift_sendDate] => 2011-10-24 
     [gift_title] => gfdgfdgdf 
     [gift_card] => 2130 
     [gift_price] => $26 
     [module] => uc_product 
) 
[title] => Gift Card 
[vid] => 2140 
[cost] => 0 
[price] => 1 
[weight] => 0 
[module] => uc_product 
[model] => giftcard 
) stdClass Object ( [cart_item_id] => 319299 
[cart_id] => 1 
[nid] => 2140 
[qty] => 15 
[changed] => 1319485739 
[data] => Array ( 
     [gift_description] => ghgfdhfghfh 
     [gift_email] => hgffghhg@gjfdhjk.com
     [gift_sender] => gfdhgfdhgfdhgf 
     [gift_sendDate] => 2011-10-24 
     [gift_title] => gfdgfdgdf 
     [gift_card] => 2130 
     [gift_price] => $26 
     [module] => uc_product 
) 
[title] => Gift Card 
[vid] => 2140 
[cost] => 0 
[price] => 1 
[weight] => 0 
[module] => uc_product 
[model] => giftcard 
) ... etc

Now what I want to do is loop through each one of these sets (foreach for example) and take the data price and title and assign it to price and title. So I would end up with.

stdClass Object ( [cart_item_id] => 319299 
[cart_id] => 1 
[nid] => 2140 
[qty] => 15 
[changed] => 1319485739 
[data] => Array ( 
     [gift_description] => ghgfdhfghfh 
     [gift_email] => hgffghhg@gjfdhjk.com
     [gift_sender] => gfdhgfdhgfdhgf 
     [gift_sendDate] => 2011-10-24 
     [gift_title] => gfdgfdgdf 
     [gift_card] => 2130 
     [gift_price] => $26 
     [module] => uc_product 
) 
[title] => Gift Card 
[vid] => 2140 
[cost] => 0 
[price] => 1 
[weight] => 0 
[module] => uc_product 
[model] => giftcard 
) stdClass Object ( [cart_item_id] => 319299 
[cart_id] => 1 
[nid] => 2140 
[qty] => 15 
[changed] => 1319485739 
[data] => Array ( 
     [gift_description] => ghgfdhfghfh 
     [gift_email] => hgffghhg@gjfdhjk.com
     [gift_sender] => gfdhgfdhgfdhgf 
     [gift_sendDate] => 2011-10-24 
     [gift_title] => gfdgfdgdf 
     [gift_card] => 2130 
     [gift_price] => $26 
     [module] => uc_product 
) 
[title] => Gift Card 
[vid] => 2140 
[cost] => 0 
[price] => 1 
[weight] => 0 
[module] => uc_product 
[model] => giftcard 
) ... etc

But I want to do it for each, now in a normal array I would loop through each set ($item in this instance) and take the $item->data[‘price’] and assign it to $item[$x]->price

But I have no idea how to do that in PHP. Any help?

  • 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-26T11:36:14+00:00Added an answer on May 26, 2026 at 11:36 am

    Where does the loop come from? You talk about foreach, but you have not supplied an example of something than needs to be iterated.

    You can “copy” the values like this:

    $object->title = $object->data['gift_title'];
    $object->price = (float) ltrim($object->data['gift_price'],'$');
    

    …and if you have an array of these objects that you want to loop through, you can do this:

    foreach ($arrayOfObjects as &$object) {
       // Note the use of & to get a reference and make sure we modify
       // the actual object, not a copy of it
      $object->title = $object->data['gift_title'];
      $object->price = (float) ltrim($object->data['gift_price'],'$');
    }
    
    • 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 data: [steamid] => stdClass Object ( [0]
I have this array: stdClass Object ( [nid] => 218 [node_title] => This is
I have array result like this: Array ( [0] => stdClass Object ( [id_global_info]
I have an piece of my array here: [0] => stdClass Object ( [id]
I have the following array called $order (as printed out by print_r): stdClass Object
I have the following array: $myarray = Array ( [1] => stdClass Object (
I have various objects that look like this: Array ( [0] => stdClass Object
I have an array that outputs these values: Array ( [0] => stdClass Object
i have array+object like this. Array ( [0] => stdClass Object ( [tid] =>
I have two arrays, Array ( [0] => stdClass Object ( [id] => 1

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.