0

These multi-dimensional arrays are giving me a headache. Here's the array, and I'm trying to pull just the [asin] value. This is from a Wordpress plugin, and here's how I dumped the array:

print "<pre>";
print_r($this);
print "</pre>";

*output:

THEPLUGIN_Template_Handler Object
(
[inline:THEPLUGIN_Template_Handler:private] => 
[is_widget:THEPLUGIN_Template_Handler:private] => 
[timestamp_template:THEPLUGIN_Template_Handler:private] => 0
[store] => 
[atts] => Array
    (
        [template] => widget-vertical-custom
        [star_rating_size] => large
        [image_size] => large
    )

[type] => box
[items] => Array
    (
        [B009FUF6DM] => Array
            (
                [id] => 18
                [status] => active
                [asin] => B009FUF6DM
....

I tried:

    echo $this->items[0];
    echo $this->items[0][0];
    echo $this['items'][0];
    echo $this['items']['B009FUF6DM']['asin'];
    echo $this->items['B009FUF6DM']['asin'];

To clarify, if I use this code echo $this->items['B009FUF6DM']['asin']; it does display the ASIN, but the problem is that the 'B009FUF6DM' value changes. So I need to account for that by just accessing the [0] index of that array, or something.

Similar to How to get data from array in object and PHP Multidimensional Array Searching (Find key by specific value)

Thanks for any help or direction! :)

jaredwins
  • 87
  • 1
  • 7

1 Answers1

0

The top level is an object, so to access items you need to access it as an attribute.

$this->items['B009FUF6DM']['asin'];

From somewhere else, if the attribute is private you need to provide a public getter for the attribute.

Juan
  • 5,525
  • 2
  • 15
  • 26
  • this helps, but my issue is that the asin value changes. If I enter this code: `echo $this->items['B009FUF6DM']['asin'];` it does display the asin, `B009FUF6DM`, but I need to access like the [0] index for that array, something like: `echo $this['items'][0]['asin'];` – jaredwins Sep 02 '18 at 16:16
  • You asked about reaching that element based on the the print_r(). Now you are asking something different. I suggest you open another question and provide the information relevant to this other matter. – Juan Sep 02 '18 at 16:22
  • I updated my question to clarify that :) sorry for the confusion – jaredwins Sep 02 '18 at 16:26