Mam takie coś i chciałbym zapisać to:
<article class="box-post">
...
</article><!-- // .box-post -->
aby kod poniżej zadziałał:
$posts['traveler'] = [
<<<'EOP'
<article class="box-post">
...
</article><!-- // .box-post -->
EOP
, <<<'EOP'
<article class="box-post">
...
</article><!-- // .box-post -->
EOP
, <<<'EOP'
<article class="box-post">
...
</article><!-- // .post-box -->
EOP
, <<<'EOP'
<article class="box-post">
...
</article><!-- // .box-post -->
EOP
];
$id = isset($_POST['id']) ? (int)$_POST['id'] : 0;
$count = isset($_POST['count']) ? (int)$_POST['count'] : 10;
$demo = isset($_POST['demo']) && isset($posts[$_POST['demo']]) ? $_POST['demo'] : 'sportsman';
$_posts = [];
for ($i = 1; $i <= $count; $i++) {
$_id = $id-$i;
if (isset($posts[$demo][abs($_id)-1])) {
$_posts[] = [
'id' => $_id,
'content' => $posts[$demo][abs($_id)-1]
];
}
}
echo json_encode([
'posts' => $_posts
]);
A to struktura JSON:
{
"posts": [
{
"id": 15,
"content": "..."
},
{
"id": 14,
"content": "..."
}
...
]
}
Proszę o jakąkolwiek poradę, wszelkie bluźnierstwo w moją stronę mile widziane :)