如何在对象PHP中添加没有值的键

时间:2016-07-31 22:20:44

标签: php

我正在尝试浏览我的文件并根据" .php"进行排序。和" .html"。 (我希望它们首先出现)

µ

这输出: [" hello.php"," index.php"];

$ files包含: [" something.txt"," test.txt"];

我想要的输出是: [" hello.php"," index.php"," something.txt"," test.txt"];

如何实现这一目标?

1 个答案:

答案 0 :(得分:1)

您可以使用array_merge组合这两个数组:

$combined = array_merge($pages, $files);
echo json_encode($combined);

组合数组示例:https://3v4l.org/0vE0F