CodeIgniter Forums

Full Version: Move array pointer?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi guys

I need to move an array pointer from another method.

Here are my codes

Code:
class Language extends MY_Controller
{
   public $fruits = array();

   
   function __construct()
   {
       parent::__construct();
       $this->load->model('qa_mdl');
       
       $this->fruits = array('apple', 'orange', 'mango', 'banana', 'guyabano');
       
   }

   
    //show current array pointer position/value
   public function idx()
   {
       $this->load->helper('array');
       
       showArray($this->fruits);
       
       $position = current($this->fruits); // $mode = 'foot';
       echo 'Current index ===> '. $position .'<br>';
   }  
   
    
    //Move array pointer one step forward
   public function move_idx()
   {
       next($this->fruits);
       redirect('language/idx/');
   }
}

I have a  button called "Next".
When this button was pressed it will call move_idx() method to move the pointer one step forward.

The problemis when I tested this it did not work. 
The pointer did not move one step forward..

Would anyone like to help me?
What's the proper way to do this?

Thanks in advance.