I'm trying to remove the first two items in an Object. For example, if I wanted to remove the first two items from an array, I'd use array_slice($arrayName, 2).
I've tried this on my object (Hey, why not? I know it's not technically an array, but I'm optimistic) and it didn't work.
When searching for this, all I found were methods for removing items from arrays.
$categories = array_slice(Mage::getModel('catalog/category')->getCollection()->addAttributeToSelect('*'), 2);
foreach($categories as $category){
echo "<div class='col'>{$category->getName()}</div>";
}
In the example above, I'd like to remove the first two categories from the $categories
(which are 'Root Category' and 'Default') object before running it through the foreach loop. What would be the best method to go about this? I know I could do;
if($category->getName() != 'Root Category' && $category->getName() != 'Default'){
echo $category->getName();
}
But this feels like a dirty solution.
Edit
After reading Patrick Q's comment, I realised that this is indeed an array of objects. So my question now becomes, why when applying an array_slice to this array, does it result in a blank screen? The loop works fine when array_slice is not applied.
Edit 2
Ignore the last Edit. It is an Object.
As for possible duplication, while the question (in question) did indeed help me solve my problem, I think, inherently they are different questions. This question, at it's core, centred around finding a useful alternative to array_slice() for objects. The question linked on the other hand, wants to to find a way, specifically, to filter Magento collections based on a drop-down attribute. Whilst they may have arrived at the same destination, the purpose and journey are very different.