CodeIgniter Forums
Move array pointer? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Move array pointer? (/showthread.php?tid=64896)



Move array pointer? - iridion2015 - 04-08-2016

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.