0

I have two arrays object:

$seo_items      = collect($resource->items)->values();
$api_items      = collect($api_items)->values();

And, I want to iterate these elements and add the property size, which belongs to the $api_items array to the $seo_items array.

foreach($seo_items as &$seo_item)
{
     foreach($api_items as $item) 
     {

        if($item->article_id == $seo_item->article->article_erp_id) 
        {
             $seo_item->article->size == $item->size;
             $items_result[] = $seo_item;
        }

     }
}

The problem is that I can not assign this value, because php report this error:

Undefined property: stdClass::$size

How can I do this ?

1
  • Please show result set of $seo_items and api_items Commented Jun 30, 2017 at 11:11

1 Answer 1

1

Seems it is result of typing.
You have used == ( comparison operator), which is comparing with property which doesn't exist,instead of assigning the value.

 $seo_item->article->size == $item->size;

changing it to

 $seo_item->article->size = $item->size;

Should resolve your problem.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.