A std::vector is designed for this.

If you can't use a std::vector I can see a couple of options.

1) Use an array terminator.

If your array should only contain positive numbers (for example) or numbers within a given range then you can use an illegal value (eg -1) as an array terminator.

for(int* i = arr; *i != -1; ++i)
{
    // do something with *i
}


2) Embed the length in the array.

For a numeric array you could, by convention, store its length in the first element.

for(int i = 0; i &lt; arr[0]; ++i)
{
    // do something with arr[i + 1]
}


Size of dynamic array or loop through it without knowing size
I'm stuck on the logic for a conditional that I need some help with.  I am building a project collaboration platform where users can view open projects and join them to form a team.  I've got the joining functionality working fine but I want to have a conditional set to not show the 'Join This Team' button if they are already a member of that project group.  I may already have some of what is needed to do this but I'm not entirely sure how to go about it.  (I had help writing the code I've already implemented)  Here is the code below for joining a project:

//controller

    public function join($project){

    // Set Var
    $email = $this-&gt;session-&gt;userdata('email');

    // Join User
    $this-&gt;project_model-&gt;join_project($project, $email);

    //Redirect to Project
    redirect('projects');

}


//functions in model to get the members already joined and insert

        public function get_team_members($id){

        $this-&gt;db-&gt;select('team_members.user_id, users.first_name, users.last_name, users.location');
        $this-&gt;db-&gt;from('team_members');
        $this-&gt;db-&gt;where('team_members.project_id', $id);
        $this-&gt;db-&gt;join('users', 'users.id = team_members.user_id');

        return $this-&gt;db-&gt;get()-&gt;result_array();

    }


    public function join_project($id, $email){

        // Get UserID
        $this-&gt;db-&gt;select('id');
        $this-&gt;db-&gt;from('users');
        $this-&gt;db-&gt;where('email', $email);
        $user = $this-&gt;db-&gt;get()-&gt;row_array();

        // Set Insert Data
        $data = array(

            'project_id' =&gt; $id,
            'user_id' =&gt; $user['id']

        );

        // Insert into Team DB
        $this-&gt;db-&gt;insert('team_members', $data);

    }   


//view

&lt;div class="large-4 columns widget"&gt;
        &lt;div class="row collapse top-margin"&gt;
            &lt;div class="large-4 columns"&gt;&lt;/div&gt;
            &lt;div class="large-8 column bottom-spacer"&gt;

&lt;?php $link = base_url()."project/join/".$project['project_id']; ?&gt;
&lt;a href="&lt;?php echo $link; ?&gt;" class="button primary radius extrawide"&gt;&lt;h5&gt;Join this Team&lt;/h5&gt;&lt;/a&gt;
            &lt;/div&gt;
        &lt;/div&gt;


//view for team members

foreach ($team as $member){ ?&gt;

                &lt;!-- Team Member #1 --&gt;
                &lt;div class="row collapse"&gt;
                    &lt;div class="large-4 columns"&gt;
                        &lt;img class="left" src="&lt;?php echo base_url();?&gt;assets/img/user.png" alt="user img"&gt;
                    &lt;/div&gt;
                    &lt;div class="large-8 columns member-name"&gt;
                        &lt;p class="name"&gt;&lt;strong&gt;&lt;?php echo $member['first_name']." ".$member['last_name']; ?&gt;&lt;/strong&gt;&lt;/p&gt;
                        &lt;p&gt;&lt;span&gt;&lt;?php echo $member['location'];?&gt;&lt;/span&gt;&lt;/p&gt;
                    &lt;/div&gt;
                &lt;/div&gt;

                &lt;?php } ?&gt;


Any help would be greatly appreciated.
