0

I have a small JSON file and want to check if "fullday":"no" is in a object. If this is true it needs to output no.

How can I do this with PHP?

 {
    "calendar": {
        "title": "Agenda punten",
        "agenda": [
            {
                "id":1,
                "datum": "2015-07-13",
                "title": "Titel agendapunt #1",
                "beschrijving": "Dit is een beschrijving",
                "fullday": "no"
            },
            {
                "id":2,
                "datum": "2015-07-14",              
                "title": "Titel agendapunt #2",
                "beschrijving": "Dit is een beschrijving", 
                "fullday": "yes"                                    
            }
        ]
    }
}

Thanks!

3
  • So what have you tried to achieve this? Commented Jul 14, 2015 at 11:10
  • I tried to find tut's about this but can't find anything. Commented Jul 14, 2015 at 11:11
  • Any code you have tried?? Commented Jul 14, 2015 at 11:12

1 Answer 1

2

Try this..

<?php
$json='{
    "calendar": {
                    "title": "Agenda punten",
                    "agenda": [

            {       "id":1,
                    "datum": "2015-07-13",
                    "title": "Titel agendapunt #1",
                    "beschrijving": "Dit is een beschrijving",
                    "fullday": "no"
            },
            {       "id":2,
                    "datum": "2015-07-14",              
                    "title": "Titel agendapunt #2",
                    "beschrijving": "Dit is een beschrijving", 
                    "fullday": "yes"                                    
            }
        ]
    }
}';

$data=json_decode($json,true);
$getdata=$data['calendar']['agenda'];

foreach($getdata as $value)
{
    if($value['fullday']=='no')
    {
        echo 'Title:'.$value['title'].'</br>';
    }
}
?>

Answer-> Title:Titel agendapunt #1

Sign up to request clarification or add additional context in comments.

1 Comment

I have posted my answer check it and let me know

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.