foreach循环计数功能总计

时间:2017-07-06 12:06:12

标签: laravel foreach

我想在count variable$nb_quota_lic_simples总共foreach

foreach ($equipes as $equipe) { $nb_quota_lic_simples = $equipe->catg_equipe->nb_licences; } dd($nb_quota_lic_simples); 我检查我有多少免费许可证,如果有很多设备,我想获得许可证的总数。希望有人帮助我。非常感谢提前!

其实我有:

<UserControl x:Class="CustomControls.ReportsListingControl"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         mc:Ignorable="d" 
         d:DesignHeight="100" d:DesignWidth="600">
<UserControl.Resources>
    <Style x:Key="ColumnHeaderStyle1" TargetType="{x:Type DataGridColumnHeader}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="DataGridColumnHeader">
                    <Grid Width="200" Height="35">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
                        <Label Grid.Column="0" 
                               HorizontalAlignment="Left" 
                               VerticalAlignment="Center" 
                               Width="50"
                               Content="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGridTextColumn}}, Path=Header}" />
                        <DatePicker Grid.Column="1" 
                                    HorizontalAlignment="Right" 
                                    VerticalAlignment="Center" 
                                    Width="30" 
                                    BorderThickness="0" Text="" />
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</UserControl.Resources>
<Grid>
    <DataGrid Name="DataGrid1" >
        <DataGrid.Columns>
            <DataGridTextColumn  HeaderStyle="{StaticResource ColumnHeaderStyle1}" Header="The Text I want displayed in my template label" />
        </DataGrid.Columns>
    </DataGrid>
</Grid>

1 个答案:

答案 0 :(得分:3)

尝试这样的事情

    $total = 0;
    foreach ($equipes as $equipe) {
        $total += $equipe->catg_equipe->nb_licences;               
    }
    dd($total);