PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.1
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.1
4.4.7 4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 4.4.0 4.3.9.1 4.3.9 4.3.8 4.3.7 4.1.6.9 4.1.6.9.1 4.1.6.9.2 4.1.6.9.3 4.1.6.9.4 4.1.7 4.1.7.1 4.1.7.2 4.1.7.3 4.1.7.3.1 4.1.7.3.2 4.2.0 4.2.1 All 138 releases
learnpress / inc / abstracts / abstract-array-access.php

abstract-array-access.php in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses 4.4.1, at inc/abstracts/abstract-array-access.php

100 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Class LP_Array_Access
5 */
6 class LP_Array_Access {
7
8 /**
9 * @var array
10 */
11 protected $_data = array();
12
13 /**
14 * @var int
15 */
16 protected $_position = 0;
17
18 /**
19 * LP_Array_Access constructor.
20 *
21 * @param $data
22 */
23 public function __construct( $data ) {
24 $this->_data = is_array( $data ) ? $data : (array) $data;
25 }
26
27 public function offsetExists( $offset ) {
28 if ( $offset ) {
29 return array_key_exists( $offset, $this->_data );
30 }
31
32 return false;
33 }
34
35 public function offsetSet( $offset, $value ) {
36 if ( $offset ) {
37 $this->_data[ $offset ] = $value;
38 }
39 }
40
41 public function offsetGet( $offset ) {
42 return $this->offsetExists( $offset ) ? $this->_data[ $offset ] : false;
43 }
44
45 public function offsetUnset( $offset ) {
46 if ( $this->offsetExists( $offset ) ) {
47 unset( $this->_data[ $offset ] );
48
49 return true;
50 }
51
52 return false;
53 }
54
55 /**
56 * Reset current position of answer options.
57 */
58 public function rewind() {
59 $this->_position = 0;
60 }
61
62 /**
63 * @return mixed
64 */
65 public function current() {
66 $values = array_values( $this->_data );
67
68 return $values[ $this->_position ];
69 }
70
71 /**
72 * @return mixed
73 */
74 public function key() {
75 $keys = array_keys( $this->_data );
76
77 return $keys[ $this->_position ];
78 }
79
80 /**
81 * Nex question.
82 */
83 public function next() {
84 ++ $this->_position;
85 }
86
87 /**
88 * @return bool
89 */
90 public function valid() {
91 $values = array_values( $this->_data );
92
93 return isset( $values[ $this->_position ] );
94 }
95
96 public function count() {
97 return sizeof( $this->_data );
98 }
99 }
100