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

Hello everyone,

I have an array

$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.

Depending on the array type (object or regular) it would either be



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.

Thanks for the quick reply jhackamack but unfortunately I still got errors.

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

    $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...

can you paste in the results from
echo "<pre>";
echo "</pre>";

here's the result...

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


Ah, i see the problem, you have an array under an array.

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

Try that.

That worked! Thanks a lot jhackamack :wow:

Theme © iAndrew 2016 - Forum software by © MyBB