I am trying to left rotate an array in PHP 2 times. It works correctly but there is a blank space in the array from some unknown reason. This is my code:
$a_temp = fgets($handle);
$a = explode(" ",$a_temp);
for($i = 0; $i < 2; $i++){
print_r($a);
array_unshift($a, array_pop($a));
print_r($a);
}
The file has something like this:
1 2 3
Now the output I get is:
Array
(
[0] => 1
[1] => 2
[2] => 3
)
Array
(
[0] => 3
[1] => 1
[2] => 2
)
Array
(
[0] => 3
[1] => 1
[2] => 2
)
Array
(
[0] => 2
[1] => 3
[2] => 1
)
As you can see, every time a rotate is performed, it introduces a blank space in it and during printing the array, it appears as a new line character. Any ideas what I am doing wrong?
"123\n"into an array ?$a = [1, 2, 3];. Don't know what you started with because you did not include it in your question$a = array(1,2,3);look fine with me no new lines.