0

So todays not going well in the world of PHP for fun, I'm having some issues with nested for loops in PHP - I've read somewhere that your not really meant to do this however in other places I see examples of it.

foreach ($xml->result->rowset->row as $row){
    $getMailID = $row{'messageID'};
    $body = $row;
    echo "MailIDCheck: " .$getMailID;
    echo $body;
    foreach ($mailMessage as &$rows){
        if($rows['mailID'] == $getMailID){
            $rows['mailMsg'] = $body;
        }
    }
}

The echo's are in there for testing. However where I think it should output the $getMailID and the $body at the first loop through, then go through the next foreach find the matching one and update the $rows['mailMsg']. Then start the process over again, however it doesn't seem to be doing that, it seems to be doing them all before it even hits that second, nested for each and I can't figure out why.

Any help to restore my sanity is MUCH appreciated,

Thanks, Jamie

4

1 回答 1

1

利用:

    if((string)$rows['mailID'] == (string)$getMailID){

$rows['mailID']和都是$getMailID对象SimpleXMLElement。您需要比较它们的字符串值。

于 2013-09-02T19:47:15.603 回答