json.txt
{
"result": {
"title": "İçerik",
"posts": [
{
"title": "Başlık 1",
"img": "post1.jpg",
"link": "1"
},
{
"title": "Başlık 2",
"img": "post2.jpg",
"link": "1"
},
{
"title": "Başlık 3",
"img": "post3.jpg",
"link": "0"
},
{
"title": "Başlık 4",
"img": "post4.jpg",
"link": "0"
}
]
}
}
index.php
<?php
// copy file content into a string var
$json_file = file_get_contents('json.txt');
// convert the string to a json object
$jfo = json_decode($json_file);
// read the title value
$title = $jfo->result->title;
// copy the posts array to a php var
$posts = $jfo->result->posts;
// listing posts
foreach ($posts as $post) {
echo $post->title;
}
?>
Arkadaşlar yukarıdaki örnekteki gibi yapınca postların tamamını listeleyebiliyorum. Fakat benim istediğim sadece "link": "1" olan postların listelenmesi. Bunu nasıl yapabilirim? If fonksiyonu ile yapmaya çalıştım fakat yapamadım. Şimdiden teşekkürler.