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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:15:05+00:00 2026-05-25T01:15:05+00:00

I am using a foreach ($content as $item) { to iterate through some items

  • 0

I am using a

      foreach ($content as $item) {

to iterate through some items for a shopping cart.
I need to get the value of ‘type’ from each of these items. Each $item has an array that looks like this:

  'item' => 
    object(stdClass)[6]
      public 'cart_item_id' => string '304' (length=3)
      public 'cart_id' => string '1' (length=1)
      public 'nid' => string '518' (length=3)
      public 'qty' => string '2' (length=1)
      public 'changed' => string '1314686050' (length=10)
      public 'data' => 
        array
          ...
      public 'title' => string 'Info prat om whiskey, inkl. smakprov, 50+ pers.' (length=47)
      public 'vid' => string '409' (length=3)
      public 'cost' => float 0
      public 'price' => float 125
      public 'weight' => int 0
      public 'weight_units' => string 'lb' (length=2)
      public 'module' => string 'uc_product' (length=10)
      public 'model' => string 'GUID-WHISKEY' (length=12)
  'node' => 
    object(stdClass)[42]
      public 'nid' => string '518' (length=3)
      public 'type' => string 'product' (length=7)
      public 'language' => string '' (length=0)
      public 'uid' => string '1' (length=1)
      public 'status' => string '1' (length=1)
      public 'created' => string '1313750365' (length=10)
      public 'changed' => string '1313750365' (length=10)
      public 'comment' => string '0' (length=1)
      public 'promote' => string '0' (length=1)
      public 'moderate' => string '0' (length=1)
      public 'sticky' => string '0' (length=1)
      public 'tnid' => string '0' (length=1)
      public 'translate' => string '0' (length=1)
      public 'vid' => string '409' (length=3)
      public 'revision_uid' => string '1' (length=1)
      public 'title' => string 'Info prat om whiskey, inkl. smakprov, 50+ pers.' (length=47)
      public 'body' => string '' (length=0)
      public 'teaser' => string '' (length=0)
      public 'log' => string '' (length=0)
      public 'revision_timestamp' => string '1313750365' (length=10)
      public 'format' => string '2' (length=1)
      public 'name' => string 'Admin' (length=5)
      public 'picture' => string '' (length=0)
      public 'data' => string 'a:2:{s:13:"form_build_id";s:37:"form-866c69ecddfdbb1158fea2e92629e36c";s:5:"block";a:1:{s:5:"views";a:1:{s:15:"paket_9-block_1";i:1;}}}' (length=135)
      public 'model' => string 'GUID-WHISKEY' (length=12)
      public 'list_price' => string '156.00000' (length=9)
      public 'cost' => string '0.00000' (length=7)
      public 'sell_price' => string '125.00000' (length=9)
      public 'weight' => string '0' (length=1)
      public 'weight_units' => string 'lb' (length=2)
      public 'length' => string '0' (length=1)
      public 'width' => string '0' (length=1)
      public 'height' => string '0' (length=1)
      public 'length_units' => string 'in' (length=2)
      public 'pkg_qty' => string '1' (length=1)
      public 'default_qty' => string '0' (length=1)
      public 'unique_hash' => string '15d33934667fad518c471dc9c20d9ce2' (length=32)
      public 'ordering' => string '0' (length=1)
      public 'shippable' => string '0' (length=1)
      public 'field_en_bild' => 
        array
          ...
      public 'field_image_cache' => 
        array
          ...
      public 'has_body' => string '1' (length=1)
      public 'panel_build_mode_info' => 
        array
          ...
      public 'taxonomy' => 
        array
          ...

How can I get the value of ‘type’ inside ‘node’? I would like to set it inside ‘item’. I have tried:

      $node->type;
      $node['type'];
      $item['node']->type;
  • 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-25T01:15:06+00:00Added an answer on May 25, 2026 at 1:15 am

    From your error msg Cannot use object of type stdClass as array
    I guess the $item is not array but stdClass.

    So try: $item->node->type.

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

Sidebar

Related Questions

I know how to loop through items of an array using foreach and append
Is there a way to iterate (through foreach preferably) over a collection using reflection?
I'm trying get values from a GridView using the following code: foreach (GridViewRow row
foreach (var item in ((ModelBase)Model).Stylesheets) { %> <%=item.url %> <link rel=stylesheet type=text/css href=<%= Url.Content(item.url)%>
I'm trying to split some html content using php's preg-match-all function: <li class=cat-item><a title=blabla
I am using the following while loop inside an foreach-loop to get categories from
I'm using a foreach to loop through an IList of objects in a Partial
I am using a <% foreach ...%> loop to list a collection of items
I am working on rendering a set of cart items using a user control.
<select id=DropList> @foreach (var item in Model.CategoryList) { <option value=@item.Id> @item.Name </option> } </select>

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.