mardi 5 mai 2015

Issue with getting data when traversing through an array PHP with a variable

I asked a similar question earlier but I couldn't get a clear answer to my issue. I have a function "isParent" that gets 2 pieces of data. Each 1 of the 2 gets a string separating each value with a , or it just gets a plain int and then checks if the first value given is a parent of the second.

I pull the 2 bits of data in and explode them but when I go through my nested for loop and try to test $toss = $arr1[$i]; print_r($toss); It comes up blank. I have no idea what the issue is: Here is the full code of the function...

function isParent($parent, $child)
{

    $parentArr = explode(',', $parent);
    $childArr = explode(',',$child);

    //Explode by Comma here. If array length of EITHER parentArr or childArr > 1 Then throw to an Else
    if(count($parentArr) <= 1 && count($childArr) <= 1) //If explode of either is > 1 then ELSE
    {
$loop = get_highest_slot(15);

for($i = $loop; $i > 0; $i--)
{
        $temp = get_membership_from_slot($i,'id_parent','id_child');

    if($temp['id_parent'] == $parent && $temp['id_child'] == $child)
    {
        return 1;
    }

}
    }
    else //set up a for loop in here so that you traverse each parentArr value and for each iteration check all child values
    {
        $i = count($parentArr);

        $c = count($childArr);

        for(;$i >=0;$i--) //Loop through every parent
        {

            for(;$c >=0;$c--)
            {
                echo '<br>$i = ';
                print_r($i);
                echo '<br><br>Parent Arr at $i:';
                $toss = $parentArr[$i];
                echo $toss;
                echo '<br>';
                print_r($childArr);
                echo '<br><br>';



                if(isParent($parentArr[$i],$childArr[$c])) //THIS CAUSES AN INFINITE YES! Learn how to pull an array from slot
                {   
                    return 1;
                }

            }


        }


    }


return 0;




}

Aucun commentaire:

Enregistrer un commentaire