V
V
Vlad2017-10-31 13:47:47
JavaScript
Vlad, 2017-10-31 13:47:47

How to output characters and their reverse order in one loop?

For example, there is a value of 4, you need to display such an order of characters
*
**
***
****
***
**
*
but you need to do this in one cycle.
<?php
$a = 4;
$b = 4;
$flag = True;
for($i = 1;$i <= $a; $i++) {
echo str_repeat("+", $i);
echo "<br>";
echo str_repeat("-", $b -= 1);
}
but I can't understand what needs to be added between two str_repeat, so that the output is correct.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
VicTHOR, 2019-08-05
@fuckingawesomenigga

function brandSearch(){
    var flag = false;
    var searchForm = $('#search');
    var brands = [];
    $('.brands .sbody button').each(function() {
        if (/qwe/.test($(this).data('brand'))) {
            brands.push($(this).data('brand'));
        }
    });

    $.each(brands,function(index,value){
      console.log(value);
    });
}

R
Rsa97, 2017-10-31
@dynamofan27

You just need to write a mathematical function that will give the desired values.

$a = 4;
for ($i = 1; $i < $a*2; $i++) {
    echo str_repeat("+", 4-(abs($a-$i)));
    echo "<br>";
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question