Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7921601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T16:38:33+00:00 2026-06-03T16:38:33+00:00

I have a method in a codeigniter controller which is sometimes called through the

  • 0

I have a method in a codeigniter controller which is sometimes called through the url and sometimes called internally from another method of the controller. When I call it internally I pass an array of arguments. Simplified version of method:

(within a controller)

function get_details($args='') {

    if (isset($args['first_name'])) 
    {
        $first_name = $args['first_name'];
    } 
    else
    {
        $first_name = $this->uri->segment(3);
    } 

    ... do some other stuff ...

}

The method is either called as:

<domain>/<controller>/get_details/abcd/efgh 

or from another function of the controller as:

$this->get_details(array('first_name'=>'abcd', 'last_name'=>'efgh'));

I was expecting that when the method was called through the url, isset($args[‘first_name’]) would be false, however it seems that called in this way the argument is there. I tried printing a couple of things and this is what I got:

print_r($args)  ---->   abcd

echo($args['first_name'])  ----> a

echo($args['whatever_index_I_use'])  ----> a  

It seems like the third parameter of the url is being passed into the method (by codeigniter?), but can’t work out why the array indexes seem to be set, all I can think is that php is converting the string to an int, so $args['whatever_index_I_use'], becomes $args[0]??

Not sure if this is a codeigniter thing or me missing a subtlety of php.

Much appreciate anyone who can explain what’s going on.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T16:38:37+00:00Added an answer on June 3, 2026 at 4:38 pm

    I don’t know if this is a bug or a expected behavior, but in the Strings docs there’s a comment that show exactly what are you experiencing. If you use a text and index of the string it will return the first char. To avoid it, check first if the argument is an array or a string:

    if(is_array($args)) {
        echo($args['first_name']);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

CodeIgniter has a method $this->load->vars($array) that is ideally used in the parent Controller to
In Kohana/CodeIgniter, I can have a URL in this form: http://www.name.tld/controller_name/method_name/parameter_1/parameter_2/parameter_3 ... And then
I have 2 functions/methods in the same controller in CodeIgniter like this: public function
Im newbie here.I have a problem with codeigniter segment() method.I referred 6th segment of
i am using codeigniter. i have class Orders which with some methods like start_order(),
I create small application which is media player. I have method where I have
I have a method in my application which retrieves the last saved image in
I have seen many php scripts in which you can cascade class method to
I have a small codeigniter controller. Below is the code class Example extends CI_Controller
If CodeIgniter has _remap() that gets called before it touches any method in a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.