I have an array
$rel = array('grandfather' => 0 ,
'grandmother' => 0 ,
'father' => 0 ,
'sister' => 0 ,
);
I want it to compare to the array $family from
$data['family'] = $facebook->api('/me/family?fields=name,relationship,education,location,cover');
using the foreach loop
foreach ($family as $families) {
foreach ($families as $fams) {
$id = $fams['id'];
$name = $fams['name'];
$relationship = $fams['relationship'];
foreach($rel as $k => $val){
if($k == $relationship)
{
$val += 1;
}
}
}
}
i want the $val
to increment in each iteration such that if I have 5 sisters.. when i will
print_r($rel);
the result would be
Array ( [grandfather] => 0 [grandmother] => 0 [father] => 0 [sister] => 5 )
i have tried the above code but it still returns to 0..
foreach($rel as $k => $val)
in here, $k is the index; if the index of the array is numbered (instead of text:$array(0 => "value")
instead of$array("txt" => "value");
) the $k will represent a number. Otherwise you could always attach a$inc=0
before the foreach and then$inc++
within the foreach – MoshMage Aug 26 '14 at 9:06