我试图在遇到新名称时在行之间添加<hr>
标记。如何在查询结果集的唯一行之间添加<hr>标记?
$conn = new mysqli("localhost", "root", "", "test");
$rs = $conn->query("SELECT * FROM usuarios");
$info = [];
$i = 0;
while($rows = $rs->fetch_array()) {
$info[$i]["pass"] = $rows["pass"];
$info[$i]["name"] = $rows["name_real"];
$i++;
}
// I want to print a line just after the last duplicated value
for($i = 0; $i < count($info) - 1; $i++) {
if($info[$i]["name"] !== $info[$i +1]["name"] && // some duplicate condition) {
$info[$i]["line"] = "<hr>";
};
}
这是从结果集中构建我的info
数组的结构。
Array
(
[0] => Array
(
[pass] => 12
[name] => Martin
)
[1] => Array
(
[pass] => 20
[name] => Martin
)
[2] => Array
(
[pass] => 2
[name] => Martin
)
[3] => Array
(
[pass] => 2
[name] => Alberto
)
)
我期望的结果会是这样的:
<p>Martin<p>
<p>Martin<p>
<p>Martin<p>
<hr>
<p>Alberto<p>
那你试试这么远吗? – Dekel
@Dekel你好!,我已经试过这个https://stackoverflow.com/questions/18438140/find-duplicate-value-in-multi-dimensional-array/18438311#18438311和其余的答案,但似乎并没有为我工作:/ – Madtin
[可能重复](https://stackoverflow.com/questions/25221390/php-count-duplicate-values-within-two-dimensional-array-then-display-only-uni) – Matt