Home php Mexican wave

Mexican wave

Author

Date

Category

How to make a wave of such a sample:

["Hello", "Hello", "Hello", "Hello", "Hello"]

code is, but it gives a little not true result:

function wave ($ people) {
  $ array = [];
  $ i = 0;
    While ($ I & LT; Strlen ($ PEOPLE)) {
      $ people [$ i] = STRToupPer ($ PEOPLE [$ i]);
      $ array [] = $ PEOPLE;
      $ i ++;
    }
  VAR_DUMP ($ array);
}
Echo Wave ('Hello');

Answer 1, Authority 100%

Let’s say so

function wave ($ people) {
$ array = [];
$ i = 0;
  While ($ I & LT; Strlen ($ PEOPLE)) {
    $ temp = $ people;
    $ TEMP [$ i] = Strtoupper ($ PEOPLE [$ i]);
    $ array [] = $ temp;
    $ i ++;
  }
VAR_DUMP ($ array);
}
Echo Wave ('Hello');

No need to rub each time the previous value.


Answer 2

function wave ($ sting) {
  For ($ i = 0; $ I & LT; Strlen ($ Sting); ++ $ i) {
    if ($ Sting [$ i] == '') Continue;
    $ Result [] = substr_replace ($ Sting, StrToupper ($ Sting [$ i]), $ i, 1);
  }
  Return $ Result;
}
Print_R (Wave ('Hello World'));

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions