- str_split: documentation ( source)
<?php
$str = 'i need healing';
function matrix($input) {
$inputIdx = str_split($input);
$inputLen = strlen($input);
for ($i = 0; $i < $inputLen; $i++) {
for ($j = 0; $j < $inputLen; $j++) {
$key = $i + $j;
if (!array_key_exists($i+$j, $inputIdx)) {
$key -= $inputLen;
}
echo $inputIdx[$key];
}
echo PHP_EOL;
}
}
matrix($str);