i got the result my for loop :
FFFF
AAAA
TTTT
EEEE
while mod=4 my loop echo br
but i want result like this :
FATE
FATE
FATE
FATE
how i do this in php ? thanks for answers and sorry my english:D
i got the result my for loop :
FFFF
AAAA
TTTT
EEEE
while mod=4 my loop echo br
but i want result like this :
FATE
FATE
FATE
FATE
how i do this in php ? thanks for answers and sorry my english:D
This is almost a duplicate of:
This can be done with foreach loops, but I like the condensed variadic method (PHP 5.6+). You can research the aforementioned links to see the other techniques if your version isn't high enough or you want something different.
The strings just need to be converted to arrays before rotating, then imploded()
after rotating.
Code: (Demo)
$input=['FFFF','AAAA','TTTT','EEEE'];
$rotated=array_map(function(){return implode(func_get_args());},...array_map('str_split',$input));
var_export($rotated);
Output:
array (
0 => 'FATE',
1 => 'FATE',
2 => 'FATE',
3 => 'FATE',
)
Here is a less fancy method to achieve the same result:
$input=['FFFF','AAAA','TTTT','EEEE'];
$length=strlen($input[0]);
foreach($input as $string){
for($offset=0; $offset<$length; ++$offset){
if(!isset($rotated[$offset])){$rotated[$offset]='';}
$rotated[$offset].=$string[$offset];
}
}
var_export($rotated);