0

I've tried to make a apply a simple sorting technique like Insertion method, and I've got this annoying error. I'm using PHP 7.

<br />
<b> Notice:  Array to string conversion in <b>[...][...]</b> on line <b>21</b><br /> Array

The line 21 is where I call echo Interschimbare

The code is as following:

<?php
function Interschimbare(array $Vector) : array{
  $N = count($Vector);
for($i = 0; $i < $N - 1; $i++)
{
    for($j = $i + 1; $j < $N; $j++)
    {
        if($Vector[$i] > $Vector[$j])
        {
            $aux = $Vector[$i];
            $Vector[$i] = $Vector[$j];
            $Vector[$j] = $aux;
        }
    }
}
return $Vector;
}

$test = [3, 0, 2, 5, -1, 4, 1];

//print_r(Interschimbare($test)); // with this line works just fine
echo Interschimbare($test);

With echo doesn't work but with print_r works just fine

1 Answers1

0

:) your variable $Vector is an array so you need to convert it to string in order to use echo.

for example:

echo implode(",",Interschimbare($test));

output will be:

-1,0,1,2,3,4,5