Hi all,
Been really trying to get a grips with objects in PHP. I think my lack of understanding isn't helping here! Basically, with the help of another user here I managed to filter some object values and add them a nice array. I used the following code:
$i = 0;
foreach ($itemsArray as $key => $obj2)
{
foreach($obj2 as $key2 => $value)
{
if($key2 == 'name' || $key2 == 'qty' || $key2 == 'line_total')
{
$iteminfo[$i][] = $value;
}
}
$i++;
}
However, later on in my code, I want to add a different object to an array. Here I use this code:
$response[] = $html->data->identifier;
I want to know how I would use that approach in the first example, because that notatation makes more sense. The original object format looked like:
stdClass Object
(
[356] => stdClass Object
(
[name] => steel wool 3
[qty] => 1
[other values]....
)
)
But there is a more pressing issue. I want to the values from $iteminfo and $response into one. To do that, I am using the following under a foreach:
$response[$i][] = $qty;
I figured that this would add the $qty value underneath the value from $responses. However, I get the error: '[] operator not supported for strings'.
When I get rid of the $i and just have $response[] it works fine. Really confused what is happening here, is the $qty value not a real value at this point or is it still an object?