gpt4 book ai didi

PHP删除结构内数组中的重复结果

转载 作者:搜寻专家 更新时间:2023-10-31 21:52:06 25 4
gpt4 key购买 nike

我在一个结构内创建了一个语言循环,它在 radio 中返回结果,我需要返回用户在此 foreach 之前选择的最后一个选择...在这段代码中,我得到了重复的结果,选中的结果和未选中的结果。如何显示不重复检查的结果?

<?php
// to select the language that insert in table "x_language" for this user
// the result is 1 in this case
$usuario_id = $this->session->userdata('usuario_id');
$usuario_id = $this->cake->get_current_language_to_user($usuario_id);
// to get all languages from table "y_languages"
$paises = $this->cake->get_paises();
$i = 0;
foreach($paises as $pais){
// here i get to checked the "y_languages" -> "$pais->nome" that have the same result on "x_language"
if($usuario_id['nome'] == $pais->nome){echo "<div class='radio iradio'><label><input type='radio' checked='checked' name='languageselected' value='".$pais->id_pais."'> ".$pais->nome."</label></div>"; }
++$i;
echo "<div class='radio iradio'><label><input type='radio' name='languageselected' value='".$pais->id_pais."'> ".$pais->nome."</label></div>";

if($i%17===0) {
echo "</div></div><div class='col-lg-2'><div class='radio iradio'>";
}
}
?>

最佳答案

希望这会奏效:

<?php
// to select the language that insert in table "x_language" for this user
// the result is 1 in this case
$usuario_id = $this->session->userdata('usuario_id');
$usuario_id = $this->cake->get_current_language_to_user($usuario_id);
// to get all languages from table "y_languages"
$paises = $this->cake->get_paises();
$i = 0;
//Getting unique from array
$paises_unq = array_unique($paises[0]);
foreach($paises_unq as $pais){
// here i get to checked the "y_languages" -> "$pais->nome" that have the same result on "x_language"
if($usuario_id['nome'] == $pais->nome){echo "<div class='radio iradio'><label><input type='radio' checked='checked' name='languageselected' value='".$pais->id_pais."'> ".$pais->nome."</label></div>"; }
++$i;
echo "<div class='radio iradio'><label><input type='radio' name='languageselected' value='".$pais->id_pais."'> ".$pais->nome."</label></div>";

if($i%17===0) {
echo "</div></div><div class='col-lg-2'><div class='radio iradio'>";
}
}
?>

关于PHP删除结构内数组中的重复结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39844250/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com