Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我的数组没有在php上排序_Php_Arrays_File_Sorting - Fatal编程技术网

我的数组没有在php上排序

我的数组没有在php上排序,php,arrays,file,sorting,Php,Arrays,File,Sorting,我试图对从文件中读取的数组进行排序。我的代码执行,但文件中的数组没有排序。你知道我遗漏了什么吗 <?php $file = fopen("text.txt","at"); $Array = file("text.txt"); rsort($Array); fclose($file); ?> 上面的代码将对内存中的$Array进行排序,但不会将排序后的数组写回文件。这将写回排序后的输出 file_put_contents("text.txt", $Array) 下面是经过修

我试图对从文件中读取的数组进行排序。我的代码执行,但文件中的数组没有排序。你知道我遗漏了什么吗

<?php
$file = fopen("text.txt","at");

$Array = file("text.txt");

rsort($Array);

fclose($file);

?>

上面的代码将对内存中的$Array进行排序,但不会将排序后的数组写回文件。这将写回排序后的输出

file_put_contents("text.txt", $Array)
下面是经过修改的代码(使用
print\r
语句来说明排序):

致:


上面的代码将对内存中的$Array进行排序,但不会将排序后的数组写回文件。这将写回排序后的输出

file_put_contents("text.txt", $Array)
下面是经过修改的代码(使用
print\r
语句来说明排序):

致:


嗨,你们想按降序排列数组吗?你们怎么知道的<代码>打印($Array)我希望您不要期望它与该代码一起写回文件。您好,您想按降序排列数组吗?您怎么知道<代码>打印($Array)我希望您不要期望它与该代码一起写回文件。谢谢。您正在编写一个只对内存中的数组进行排序,而没有对实际文件进行更改的文件。再次感谢您的帮助。如果可以,请将问题标记为已回答!谢谢您正在编写一个只对内存中的数组进行排序,而没有对实际文件进行更改的文件。再次感谢您的帮助。如果可以,请将问题标记为已回答!
Z
D
A
C
Z
D
C
A