0

My object is something like this

object(Magento\Framework\Data\Collection)[8565]
protected '_items' => 
 array (size=3)
  15841610 => 
    object(Magento\Framework\DataObject)[8701]
      protected '_data' => 
        array (size=28)
          ...
  15841611 => 
    object(Magento\Framework\DataObject)[8750]
      protected '_data' => 
        array (size=28)
          ...
  15841612 => 
    object(Magento\Framework\DataObject)[8563]
      protected '_data' => 
        array (size=28)

whats that '_items' string, how can I move the last element with key = 15841612 to the first and shift others.

I have tried this with an array but for the object, it doesn't work.

0

Here you have a collection model with _items property which holds all collection's items as array (and each element in array will be instance of Magento\Framework\DataObject class). You can't move it inside the collection and then use collection with new order of items there (if you need that way, you can use conditions in prepared select), but instead you can get items from collection (once again, here you will have an array) and do manipulations as with array in PHP, so to do it (in case, if you want to move LAST element to the beginning on the items array):

$items = $yourCollection->getItems();
$lastItem = array_pop($items);
array_unshift($items, $lastItem);
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.