# notificationx/1.1.1/includes/class-nx-array.php

NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner &amp; Floating Notification Bar, version 1.1.1. 70 lines.

- Page: https://pluginprobe.com/plugins/notificationx/1.1.1/code/includes/class-nx-array.php
- Raw: https://pluginprobe.com/plugins/notificationx/1.1.1/raw/includes/class-nx-array.php
- Modified: 2019-07-16T10:38:30+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/notificationx/1.1.1/code/includes/class-nx-array.php#L10-L20`.

```php
<?php

/**
 * This class is responsible for Handling Array.
 */

class NotificationX_Array {
    private $limit = 5;
    private $values;
    private $priority = [];
    public $sortBy = 'priority';

    public function setValues( $values ) {
        $this->values = $values;
        $this->sort();
    }

    public function values() {
        $this->values = array_slice( $this->values, 0, $this->limit );
        return $this->values;
    }
    public function setLimit( $limit = 5 ) {
        $this->limit = $limit;
    }

    public function size(){
        return count( $this->values );
    }

    public function sort( $flags = SORT_DESC ) {
        if( empty( $this->values ) ) {
            return $this;
        }
        foreach( $this->values as $key => $value ) {
            $this->priority[ $key ] = $value[ $this->sortBy ];
        }
        array_multisort( $this->priority, $flags, $this->values );
        $this->priority = [];
        return $this;
    }

    public function append( $value, $key = null ) {
        if( $this->size() == $this->limit ) {
            $this->sort();
            array_pop( $this->values );
        }
        if( $key === null ) {
            array_push( $this->values, $value );
        } else {
            $this->values = $this->values + [ $key => $value ];
        }
        $this->sort();
        return $this;
    }

    public function prepend( $value, $key = null ){
        if( $this->size() == $this->limit ) {
            $this->sort();
            array_pop( $this->values );
        }

        if( $key === null ) { 
            array_unshift( $this->values, $value );
        } else {
            $this->values = [ $key => $value ] + $this->values;
        }
        $this->sort();
        return $this;
    }
}
```
