数组空外foreach循环

时间:2017-09-13 12:33:19

标签: php foreach

我收到了以下代码:

<Page
    x:Class="CloserCrumbs.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:CloserCrumbs"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Page.DataContext>
        <local:SuperVM />
    </Page.DataContext>

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <ListView ItemsSource="{Binding Steps}" SelectedItem="{Binding Steps.SelectedItem, Mode=TwoWay}" Height="40" FocusVisualPrimaryThickness="0" FocusVisualSecondaryThickness="0">
            <ListView.ItemsPanel>
                <ItemsPanelTemplate>
                    <StackPanel Orientation="Horizontal" />
                </ItemsPanelTemplate>
            </ListView.ItemsPanel>

            <ListView.ItemTemplate>
                <DataTemplate>
                    <StackPanel x:Name="t1" Orientation="Horizontal" Margin="-12" Height="30">

                        <Grid Height="30">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition/>
                            </Grid.ColumnDefinitions>
                            <StackPanel Orientation="Horizontal" Margin="0,0,-7,0" Height="30" >
                                <Path Data="M0,0 10,0 10,30 0,30 10,15" Fill="#d0d0d0" />
                                <Grid>
                                    <Rectangle Fill="#d0d0d0" />
                                    <TextBlock Text="{Binding ShortDescription}" Margin="10,5" VerticalAlignment="Center" Foreground="White" MinWidth="60"/>
                                </Grid>
                                <Path Data="M0,0 10,15 0,30" Fill="#d0d0d0" />
                            </StackPanel>
                        </Grid>
                    </StackPanel>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </Grid>
</Page>

$hostUptimesSum = []; foreach($hostIDs as &$hostID) { $hostUptimeDetailsQuery = "some query"; $resultHostUptimeDetails = mysql_query($hostUptimeDetailsQuery); $rowHostUptimeDetails = mysql_fetch_assoc($resultHostUptimeDetails); $totalTime = $rowHostUptimeDetails['UP_T'] + $rowHostUptimeDetails['DOWN_T'] + $rowHostUptimeDetails['UNREACHABLE_T'] + $rowHostUptimeDetails['UNDETERMINED_T'] + $rowHostUptimeDetails['MAINTENANCE_T']; array_push($hostUptimes, $rowHostUptimeDetails); $hostUptimesSum['UP_A'] += $rowHostUptimeDetails['UP_A']; $hostUptimesSum['UP_T'] += $rowHostUptimeDetails['UP_T']; $hostUptimesSum['DOWN_A'] += $rowHostUptimeDetails['DOWN_A']; $hostUptimesSum['DOWN_T'] += $rowHostUptimeDetails['DOWN_T']; $hostUptimesSum['UNREACHABLE_A'] += $rowHostUptimeDetails['UNREACHABLE_A']; $hostUptimesSum['UNREACHABLE_T'] += $rowHostUptimeDetails['UNREACHABLE_T']; $hostUptimesSum['UNDETERMINED_T'] += $rowHostUptimeDetails['UNDETERMINED_T']; $hostUptimesSum['MAINTENANCE_T'] += $rowHostUptimeDetails['MAINTENANCE_T']; $hostUptimesSum['TOTAL'] += $totalTime; array_push($values, array($hostID['host_name'], round($rowHostUptimeDetails['UP_T']/$totalTime*100,2)."%",$rowHostUptimeDetails['UP_A'], round($rowHostUptimeDetails['DOWN_T']/$totalTime*100,2)."%", $rowHostUptimeDetails['DOWN_A'] ,round($rowHostUptimeDetails['UNREACHABLE_T']/$totalTime*100,2)."%", $rowHostUptimeDetails['UNREACHABLE_A'], round($rowHostUptimeDetails['MAINTENANCE_T']/$totalTime*100,2)."%", round($rowHostUptimeDetails['UNDETERMINED_T']/$totalTime*100,2)."%",)); } var_dump($hostUptimesSum); $data = array( 'UP' => $hostUptimesSum['UP_T'], 'DOWN' => $hostUptimesSum['DOWN_T'], 'UNREACHABLE' => $hostUptimesSum['UNREACHABLE_T'], 'SCHEDULED DOWNTIME' => $hostUptimesSum['MAINTENANCE_T'], 'UNDETERMINED' => $hostUptimesSum['UNDETERMINED_T'] ); 数组在$hostUptimesSum循环之外声明。如果我在foreach循环内的数组上执行var_dump,我可以看到值正确加起来,但是当我在循环外调用var_dump时,我什么都没得到。

目前我完全没有想法。

编辑:我添加了与此特定阵列相关的所有代码。

0 个答案:

没有答案