XF 2.0 "array_column" on an ArrayCollection?

Jaxel

Well-known member
The entity finder returns an ArrayCollection.

With multi-dimensional arrays, you can use the array_column function to get an array of values based on specific keys in the array.

Is something similar available with the entity finder system?
 
No, you'd have to get the array and then perform array column on it:
PHP:
$array = $collection->toArray();
$columnArr = \XF\Uitl\Arr::arrayColumn($array, 'column'); // use our arrayColumn for pre-PHP 5.5 support
 
How can I add two collections, please?

I need to merge $this->Images and $this->Images2 for this function

PHP:
    public function getBbCodeRenderOptions($context, $type)
    {
        return [
            'entity' => $this,
            'user' => $this->User,
            'attachments' => $this->attach_count ? $this->Images : [],
            'viewAttachments' => $this->canViewProductImages()
        ];
    }
 
Works

PHP:
    public function getBbCodeRenderOptions($context, $type)
    {

        $array = $this->Images->toArray();
        $array2 = $this->Images2->toArray();
        $array3 = $array + $array2;
        
        return [
            'entity' => $this,
            'user' => $this->User,
            'attachments' => $this->attach_count ? $array3 : [],
            'viewAttachments' => $this->canViewProductImages()
        ];
    }
 
Top Bottom