Welcome Guest, Not a member yet? Register   Sign In
Newbie array question
#1

[eluser]brixxster[/eluser]
Hello everyone,

I have an array

Code:
$data['rows'] ( 'fname' => My Name, 'lname' => My Last name, 'acct_type' => 2)

I wanted to test acct_type so I can redirect to specific function according to its value. I'm using switch case for the testing, what is the correct syntax for getting the acct_type value in the array? I'm still a newbie so forgive me if this reads like a dumb question.

thanks everybody.
#2

[eluser]JHackamack[/eluser]
Depending on the array type (object or regular) it would either be

Code:
//regular
$data['rows']['acct_type']

or
Code:
//object
$data['rows']->acct_type

If you are using active record to set the $data['rows'] array then it is probably object, but if you are setting it yourself then its probably regular.
#3

[eluser]brixxster[/eluser]
Thanks for the quick reply jhackamack but unfortunately I still got errors.

Here's the snippet of the code I have in the controller...

Code:
$this->load->model('model_membervalidation');
    $data['rows'] = $this->model_membervalidation->memValidate();

    //tried this one I get error -> Message: Undefined index: acct_type
    echo $data['rows']['acct_type'];

    //I get error also -> Message: Trying to get property of non-object
    echo $data['rows']->acct_type;

I don't know what I'm doing wrong here...
#4

[eluser]JHackamack[/eluser]
can you paste in the results from
Code:
echo "<pre>";
print_r($data['rows']);
echo "</pre>";
#5

[eluser]brixxster[/eluser]
here's the result...

Code:
Array
(
    [0] => stdClass Object
        (
            [acct_id] => 1
            [fname] => brixx
            [lname] => miranda
            [mname] => jones
            [email] => [email protected]
            [cellphone] => 639162043512
            [telephone] => 63458887541
            [password] => 81dc9bdb52d04dc20036dbd8313ed055
            [acct_type] => 1
        )

)
#6

[eluser]JHackamack[/eluser]
Ah, i see the problem, you have an array under an array.

Code:
echo $data['rows'][0]->acct_type;

Try that.
#7

[eluser]brixxster[/eluser]
That worked! Thanks a lot jhackamack :wow:




Theme © iAndrew 2016 - Forum software by © MyBB