Search code examples
phparraysimplementationarrayobjectslice

array_slice (or other array_* functions) on ArrayObject


I have a question regarding ArrayObject. I wanted to use array_slice in an ArrayObject class and I couldn't. Is there a way to do it, without needing to write an "slice" method to the class that implements ArrayObject?


Solution

  • Having a class that wraps php array functions is not that bad idea. Will make code much cleaner.

    echo $myAry->slice(10, 5)->reverse()->join(", ");
    

    Just like a normal language, you know.