A
A
Anton2017-10-13 07:59:43
PHP
Anton, 2017-10-13 07:59:43

How to split an array into 2 columns?

<?foreach($arProps as $strPropName => $strPropValue){?>
                        
                            <?=$strPropName?> : <?=$strPropValue?>
                    <?}?>

Displays the name and value in a string.
How to split into 2 columns?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
O
Oleg, 2017-10-13
@politon

It is not entirely clear what to output.
If you view a beautiful print_r array, then using <pre>
If the input is in html, then use columncss or using js

E
Eugene Zubkov, 2017-10-13
@kHan_Solo

Alternatively use ul/li

<ul>
    <?php foreach($arProps as $strPropName => $strPropValue): ?>
        <li class="row">
            <span class="column"><?php echo $strPropName ?></span>
            <span class="delimiter">:</span>
            <span class="column"><?php echo $strPropValue ?></span>
        </li>
    <? endforeach; ?>
</ul>

V
Vitaly Mironov, 2017-10-13
@nor1m

//Как вариант
 $i = 0;  $br = '';
<?php foreach($arProps as $strPropName => $strPropValue) { ?>
 $i++;
if($i%2 == 0) ? $br = '<br>' : $br = '' ;
   <?= "{$strPropName} : {$strPropValue}".$br; ?>
<?php } ?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question