使用不带foreach的json解码数组

时间:2018-12-27 16:06:16

标签: php json date foreach

我有以下json:

<Button Margin="10, 0, 0, 0" >
    <Button.Style>
        <Style TargetType="Button">
            <Setter Property="Visibility" Value="Hidden"/>
            <Style.Triggers>
                <DataTrigger Binding="{Binding SelectedItem.Content, ElementName=ComboBox}" Value="Testing">
                    <Setter Property="Visibility" Value="Visible"/>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </Button.Style>
</Button>

是名字和生日。有什么方法可以使用条件搜索没有foreach的生日?

例如,“所有在$json = '[{"name":"Peter","bday":"1990-10-10"},{"name":"Mark","bday":"1992-08-10"},{"name":"John","bday":"1993-08-09"},{"name":"John","bday":"2000-05-19"}]'; 之后出生的注册表”。

谢谢

1 个答案:

答案 0 :(得分:0)

我能够使用array_filter函数

function greater_than($arr){
    $date = $arr['bday'];

    if(strtotime($date) > strtotime('1993-01-01')){
        return $date;
    }
}

$json = '[{"name":"Peter","bday":"1990-10-10"},{"name":"Mark","bday":"1992-08-10"},{"name":"John","bday":"1993-08-09"},{"name":"John","bday":"2000-05-19"}]';
$dec = json_decode($json,true);
print_r(array_filter($dec, "greater_than"));