Jump to content

Adding to a multi dimension array


djforema

Recommended Posts

I'm trying to add a value to my multi dimension array.  I want to add a 'quantity'  value to the inner array. 

 

This is what I have now:

 Array (
      [0] => stdClass Object ( 
          [0] => stdClass Object ( [name] => BRACKET [option_sku] => [value] => B-Line BB7-16 )
          [1] => stdClass Object ( [name] => BOX [option_sku] => [value] => Crouse Hinds TP40DPF )
          [2] => stdClass Object ( [name] => Mud Ring[option_sku] => [value] => Rise Single Gang )
          [3] => stdClass Object ( [name] => MC Cable[option_sku] => [value] =>black,white,green))
 
      [1] => stdClass Object ( 
          [0] => stdClass Object ( [name] => BRACKET [option_sku] => [value] => B-Line BB7-16 )
          [1] => stdClass Object ( [name] => BOX [option_sku] => [value] => Crouse Hinds TP40DPF )
          [2] => stdClass Object ( [name] => Mud Ring[option_sku] => [value] => Rise Single Gang )
          [3] => stdClass Object ( [name] => MC Cable[option_sku] => [value] =>black,white,green))
 
)

I'm trying to make it like this:

 Array (
      [0] => stdClass Object ( 
          [0] => stdClass Object ( [name] => BRACKET [option_sku] => [value] => B-Line BB7-16 [quantity] => 5 )
          [1] => stdClass Object ( [name] => BOX [option_sku] => [value] => Crouse Hinds TP40DPF [quantity] => 5)
          [2] => stdClass Object ( [name] => Mud Ring[option_sku] => [value] => Rise Single Gang [quantity] => 5)
          [3] => stdClass Object ( [name] => MC Cable[option_sku] => [value] =>black,white,green [quantity] => 5))
 
      [1] => stdClass Object ( 
          [0] => stdClass Object ( [name] => BRACKET [option_sku] => [value] => B-Line BB7-16 [quantity] => 5)
          [1] => stdClass Object ( [name] => BOX [option_sku] => [value] => Crouse Hinds TP40DPF [quantity] => 5)
          [2] => stdClass Object ( [name] => Mud Ring[option_sku] => [value] => Rise Single Gang [quantity] => 5)
          [3] => stdClass Object ( [name] => MC Cable[option_sku] => [value] =>black,white,green [quantity] => 5))
 
)

I'm trying something like this but it isn't working.

<?php

//This is the array I want to add to.

$product_options = $registry->toObject();
 

//This is the value of what I want to add to the array.  With the key being 'quantity'.         
$number = $item->orderitem_quantity;

?>

<?php foreach($product_options as $key => $quan) ?>

<?php
$product_options[$key]['quantity'] = $number;

?>

<?php endforeach; ?>
Edited by Zane
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.