If statement inside a Json object

Is it possible to add an if($count % 6 == 5): statement inside the Json representation?

I’m looking for something like this:

<?php

$data = $pages->find('materials')->files();
$json = [];
$count = 0;

foreach($data as $file) {

    $json[] = [
        'name'      => (string)$file->name(),
        'type'  => (string)$file->extension(),
        if($count % 6 == 5):
            'break' => 'true',    
        else:
           'break' => 'false',
        endif;
        'url'       => (string)$file->url(),
        'texture'   => (string)$file->material(),
    ];

}

echo json_encode($json);

Also I need to add the $count++; somewhere to make it count up. I already feel like I’m completly wrong.

I must admit that I copy pasted this from the php template in which I made the same thing work like this:

<?php 
$images = page('materialen')->files()->shuffle();
$count = 0; ?>
  
<?php foreach($images as $image): ?>

    <?php if($count % 6 == 0): ?>
        <ul class="container">
    <?php endif ?>

            <li>content…</li>

    <?php if($count % 6 == 5): ?>
        </ul>
        <ul class="panel"></ul>
    <?php endif ?>

<?php $count++; endforeach ?>

Never try to put logic inside an array:

foreach($data as $file) {
    $break = $count % 6 == 5 ? 'true' : 'false';
    $json[] = [
        'name'    => (string)$file->name(),
        'type'    => (string)$file->extension(),
        'break'   => $break,
        'url'     => (string)$file->url(),
        'texture' => (string)$file->material(),
    ];
    $count++;
}

Edited, because counter was missing.

It was a bit late here… Makes 100% sense! Thanks for the lightning fast response again :slight_smile: