title: PHP Laravel Check two arrays and unset values
body: <p>Hi im working on a project where I can assign some statuses to a <code>project</code> and these are saved in a table <code>assigned_statuses</code>. Now I am using jquery connected lists to decide how users assign them. Therefore when I load the two lists one will be populated with the assigned ones and the other with the available ones. 
  To fetch the assigned ones I have the following Model functions:</p>
  
  <p>app/models/AssignedStatus.php</p>
  
  <pre><code>public function projects() {
      return $this-&gt;belongsTo('Project');
  }
  public function statuses() {
      return $this-&gt;belongsTo('Status');
  }
  </code></pre>
  
  <p>app/models/Project.php</p>
  
  <pre><code>public function assignedProjectBoardStatuses() {
          return $this-&gt;hasMany('AssignedProjectBoardStatus','project_id')-&gt;orderBy('order','asc');
      }
  </code></pre>
  
  <p>app/models/Status.php</p>
  
  <pre><code>public function assignedProjectBoardStatus() {
          return $this-&gt;hasMany('AssignedProjectBoardStatus');
  }
  </code></pre>
  
  <p>and I call upon these as follows:</p>
  
  <p><code>$project = Project::with(['assignedStatuses', 'assignedStatuses.statuses'])-&gt;find($id);</code></p>
  
  <p>and the statuses I grab as follows:</p>
  
  <p><code>$statuses = Status::statusByOrder();</code></p>
  
  <p>Now this returns an array as follows:</p>
  
  <p><code>$project</code> array:</p>
  
  <pre><code>array(12) {
  ["id"]=&gt;
  string(1) "3"
  ["name"]=&gt;
  string(11) "Project 13"
  ["start_date"]=&gt;
  string(10) "2015-07-13"
  ["end_date"]=&gt;
  string(10) "2015-07-27"
  ["active"]=&gt;
  string(1) "0"
  ["cancelled"]=&gt;
  string(1) "0"
  ["archive"]=&gt;
  string(1) "0"
  ["deleted_at"]=&gt;
  NULL
  ["created_at"]=&gt;
  string(19) "2015-07-26 00:01:59"
  ["updated_at"]=&gt;
  string(19) "2015-07-26 00:01:59"
  ["assigned_statuses"]=&gt;
  array(4) {
  [0]=&gt;
  array(7) {
  ["id"]=&gt;
  string(1) "1"
  ["project_id"]=&gt;
  string(1) "3"
  ["status_id"]=&gt;
  string(1) "1"
  ["order"]=&gt;
  string(1) "0"
  ["created_at"]=&gt;
  string(19) "2015-07-26 00:01:59"
  ["updated_at"]=&gt;
  string(19) "2015-07-26 00:01:59"
  ["statuses"]=&gt;
  array(8) {
  ["id"]=&gt;
  string(1) "1"
  ["name"]=&gt;
  string(7) "Backlog"
  ["order"]=&gt;
  string(1) "0"
  ["created_at"]=&gt;
  string(19) "2015-07-25 23:22:54"
  ["updated_at"]=&gt;
  string(19) "2015-07-25 23:23:03"
  }
  }
  [1]=&gt;
  array(7) {
  ["id"]=&gt;
  string(1) "2"
  ["project_id"]=&gt;
  string(1) "3"
  ["status_id"]=&gt;
  string(1) "3"
  ["order"]=&gt;
  string(1) "1"
  ["created_at"]=&gt;
  string(19) "2015-07-26 00:02:00"
  ["updated_at"]=&gt;
  string(19) "2015-07-26 00:02:00"
  ["statuses"]=&gt;
  array(8) {
  ["id"]=&gt;
  string(1) "3"
  ["name"]=&gt;
  string(11) "In Progress"
  ["order"]=&gt;
  string(1) "1"
  ["created_at"]=&gt;
  string(19) "2015-07-25 23:22:54"
  ["updated_at"]=&gt;
  string(19) "2015-07-25 23:23:04"
  }
  }
  [2]=&gt;
  array(7) {
  ["id"]=&gt;
  string(1) "3"
  ["project_id"]=&gt;
  string(1) "3"
  ["status_id"]=&gt;
  string(1) "4"
  ["order"]=&gt;
  string(1) "2"
  ["created_at"]=&gt;
  string(19) "2015-07-26 00:02:00"
  ["updated_at"]=&gt;
  string(19) "2015-07-26 00:02:00"
  ["statuses"]=&gt;
  array(8) {
  ["id"]=&gt;
  string(1) "4"
  ["name"]=&gt;
  string(6) "Review"
  ["order"]=&gt;
  string(1) "2"
  ["created_at"]=&gt;
  string(19) "2015-07-25 23:22:54"
  ["updated_at"]=&gt;
  string(19) "2015-07-25 23:23:05"
  }
  }
  [3]=&gt;
  array(7) {
  ["id"]=&gt;
  string(1) "4"
  ["project_id"]=&gt;
  string(1) "3"
  ["status_id"]=&gt;
  string(1) "5"
  ["order"]=&gt;
  string(1) "3"
  ["created_at"]=&gt;
  string(19) "2015-07-26 00:02:00"
  ["updated_at"]=&gt;
  string(19) "2015-07-26 00:02:00"
  ["statuses"]=&gt;
  array(8) {
  ["id"]=&gt;
  string(1) "5"
  ["name"]=&gt;
  string(4) "Done"
  ["order"]=&gt;
  string(1) "3"
  ["created_at"]=&gt;
  string(19) "2015-07-25 23:22:54"
  ["updated_at"]=&gt;
  string(19) "2015-07-25 23:23:08"
  }
  }
  }
  }
  </code></pre>
  
  <p>and the <code>statuses</code> array:</p>
  
  <pre><code>array(5) {
  [0]=&gt;
  array(8) {
  ["id"]=&gt;
  string(1) "1"
  ["name"]=&gt;
  string(7) "Backlog"
  ["order"]=&gt;
  string(1) "0"
  ["created_at"]=&gt;
  string(19) "2015-07-25 23:22:54"
  ["updated_at"]=&gt;
  string(19) "2015-07-25 23:23:03"
  }
  [1]=&gt;
  array(8) {
  ["id"]=&gt;
  string(1) "3"
  ["name"]=&gt;
  string(11) "In Progress"
  ["order"]=&gt;
  string(1) "1"
  ["created_at"]=&gt;
  string(19) "2015-07-25 23:22:54"
  ["updated_at"]=&gt;
  string(19) "2015-07-25 23:23:04"
  }
  [2]=&gt;
  array(8) {
  ["id"]=&gt;
  string(1) "4"
  ["name"]=&gt;
  string(6) "Review"
  ["order"]=&gt;
  string(1) "2"
  ["created_at"]=&gt;
  string(19) "2015-07-25 23:22:54"
  ["updated_at"]=&gt;
  string(19) "2015-07-25 23:23:05"
  }
  [3]=&gt;
  array(8) {
  ["id"]=&gt;
  string(1) "5"
  ["name"]=&gt;
  string(4) "Done"
  ["order"]=&gt;
  string(1) "3"
  ["created_at"]=&gt;
  string(19) "2015-07-25 23:22:54"
  ["updated_at"]=&gt;
  string(19) "2015-07-25 23:23:08"
  }
  [4]=&gt;
  array(8) {
  ["id"]=&gt;
  string(1) "2"
  ["name"]=&gt;
  string(4) "Open"
  ["order"]=&gt;
  string(1) "4"
  ["created_at"]=&gt;
  string(19) "2015-07-25 23:22:54"
  ["updated_at"]=&gt;
  string(19) "2015-07-25 23:23:01"
  }
  }
  </code></pre>
  
  <p>Now this is what I have thus far:</p>
  
  <pre><code>    if(array_key_exists('assigned_statuses', $project)) {
          foreach ($project-&gt;assigned_statuses as $status) {
              $assignedIds [] = $status-&gt;id;
          }
  
          foreach ($statuses as $status) {
              $statusIds[] = $status-&gt;id;
          }
  
  
          if (in_array($assignedIds, $statusIds)) {
              unset($statusIds); 
          } else {
             //pass all available statuses...
          }
      }
  </code></pre>
  
  <p>However this doesn't reach the unset piece, I goes because the comparison of the two arrays fail. Does any know how I can compare the ids between the two arrays? In the $project array I want to check the nested array ["assigned_statuses"] against the $statuses ids. How can I achieve this successfully and unset the ones that are already assigned??</p>