I want to read out a multidimensional array which is set in an item and requested by API. But in my browser the array is always returned like this:
items:
products:
0: "{"id":"1","name":"first product"}"
1: "{"id":"2","name":"second product"}"
Instead it should look like this:
items:
products:
0:
id: 1
name: first product
1:
id:2
name:second product
My multidimensional array looks like this:
products[] = [
'product1' => [
'id' => 1,
'name' => 'first product'
],
'product2' => [
'id' => 2,
'name' => 'second product'
]]
Therefore I added my new variable/array also in the interface of this item:
/**
* @return array
*/
public function getProducts();
/**
* @param array $products
* @return $this
*/
public function setProducts($products);
In my php code I add the data in the following way to my item:
$item = $this->itemFactory->create();
$item->setData([
'products' => $products
])
Does anybody know why the multidimensional array is formatted in this way?