How To Get Last segment From URL In Codeigniter?

I need to get the value of last URI / URL segment in Codeigniter today and I came up with this easy solutions. It permits you to retrieve a last segment from the URI. ALL three alternative works like charm.
Alternative 1:
$last = end($this->uri->segments); 
//Where, segments is a class variable.
Alternative 2:
$last = end($this->uri->segment_array());
Alternative 3:
$total = $this->uri->total_segments();
$last = $this->uri->segment($total);

Comments

Post a Comment

Popular Posts