Question: I have an array:

```
    $data = array(
        'loggedin' => false
    );

```

i want to add other keys as well their values if the user is logged in so i use:

```
    if ( $this->auth_model->loggedin()){//user is logged in
        $data["loggedin"] = true;//set to true
        $data["user_id"] = $this->session->userdata["uid"];//add new key with its value on $data array
    }

```

is this the best way to do it or should i use `array_push` and such?

Answer: 
No need to add overhead by calling a function (like array\_push).

Yes. That's the way to do it.
With `array_push` you cannot set the key.

The way you have described is the fastest one.

You can create a second array with `user_id` key and then merge those two arrays, but this is not a good way to solve this case.

Stay with that you have right now.