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?
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:
…and if you have an array of these objects that you want to loop through, you can do this: