遍历数组,并对每个值运行函数


Itirate through array, and run function on each value

我需要遍历一个数组,并编辑每个值,但不能有不同。

<?php
Function parseStatus($Input, $Start, $End){
    $String = " " . $Input;
    $Init = StrPos($String, $Start);
    If($Init == 0){
        Return '';
    }
    $Init += StrLen($Start);
    $Length = StrPos($String, $End, $Init) - $Init;
    Return SubStr($String, $Init, $Length);
}
Function getAllStatuses($Username){
    $DOM = new DOMDocument();
    $DOM->validateOnParse = True;
    @$DOM->loadHtml(File_Get_Contents('http://lifestream.aol.com/stream/' . $Username));
    $xPath = new DOMXPath($DOM);
    $Stream = $DOM->getElementById('stream')->nodeValue; // return stream content for display name
    $Nodes = $xPath->query('//div[@class="stream"]');
    $Name = Explode(' ', Trim($Stream));
    $User = $Name[0];
    $Statuses = Array();
    ForEach($Nodes as $Node){
        ForEach($Node->getElementsByTagName('li') as $Key => $Tags){
            $Statuses[] = $Tags->nodeValue;
        }
    }
    ForEach($Statuses as $Status){
        If(StrPos($Status, 'Services')){
            Echo 'services is definitely in there';
            $New = AIM::parseStatus($Status, $User, 'Services');
            Echo $New;
            Break;
        }
    }
?>

问题是,$New只回显第一个输出,但我如何让它贯穿数组中的每个值,并做同样的事情?

预期输出:[名称作为开始]我需要什么[文字服务]

然后对数组中的每个值执行相同的操作,使其看起来像:

我需要什么

再次我需要什么,但不同的字符串

等等。

谢谢你的帮助。

foreach循环中的Break;就是破坏循环。

卸下Break;,它应该可以工作。

请在此处阅读:
http://www.php.net/break

break结束当前for、foreach、while、do-while或switch结构的执行。