I'm trying to come up with a way to work with what could potentially be a very large set of arrays. What i am doing is working with facebook api schedule.
Therefore, when a user subscribes to the service that I create, I store my facebook id in a table in my service. The essence of this is to allow a user who subscribes to my service to find friends of their users on Facebook and also register with my service to make it easier to find each other.
What I'm trying to do at the moment is to take the object that the facebook api returns for the data /me/friendsand pass it to the function that I create in my database for the identifier found in the FB data, which works well. Also, while this whole bit continues, I only have an array to create a facebook id, so I can use them in a script in_array. Since my query only returns the facebook id matching
While this data is sorted by itself to create a query, I also update the object to contain another key / value pair for each item in the list, which is equal "are_friends"=> false. So far, all this has worked smoothly and relatively quickly, and I have the results of my query. Which I'm looping.
So, I am in the part where I want to avoid loop in loop. This is where the bit in_array()comes. Since I created an array of the saved fb identifier, now I can iterate over my results to see if there is a match, in which case I want to take the original object that I added 'are_friends'=>falseto and change those that correspond to "true" instead of false. I just can't think of a good way without looping over the original array inside the loop, which is an array of results.
So I hope someone can help me come up with a solution here without this secondary loop
An array to this point starting from the original looks like
Array(
[data](
[0] => array(
are_fb_friends => false
name => user name
id => 1000
)
[1] => array(
are_fb_friends => false
name => user name
id => 2000
)
[2] => array(
are_fb_friends => false
name => user name
id => 3000
)
)
)
As per request
This is my current code logic, which I am trying to describe above.
public function fromFB($arr = array())
{
$new_arr = array();
if((is_array($arr))&&(count($arr) > 0))
{
$this->db->select()->from(MEMB_BASIC);
$first_pass = 0;
for($i=0;$i < count($arr);$i++)
{
$arr[$i]['are_fb_friends'] = "false";
$new_arr[] = $arr[$i]['id'];
if($first_pass == 0)
{
$this->db->where('facebookID', $arr[$i]['id']);
}
else
{
$this->db->or_where('facebookID', $arr[$i]['id']);
}
$first_pass++;
}
$this->db->limit(count($arr));
$query = $this->db->get();
if($query->num_rows() > 0)
{
$result = $query->result();
foreach($result as $row)
{
if(in_array($row->facebookID, $new_arr))
{
array_keys($arr, "blue");
}
}
}
}
return $arr;
}