douzhi6365 2019-06-11 08:18
浏览 116
已采纳

作为数组值的函数

I have a function with the data I received from json and the student name and surname. I don't have any problems when there is only one student number, but if there are two students in the incoming data, the student number comes in the array. What should I do in this case?

if($adi =="Turkce")
{
    $tip = "DuzMantik";
    $values = array();
    foreach($olan->selections as $solan){

        $og_numarasi = $solan->description;
        $notum = $solan->note;

        $ogrneci_adi = ogrenciadial($yil,$hafta,$og_numarasi);
        $values[] = array("tur"=>$og_numarasi,"tid"=>$ogrneci_adi,"not"=>$notum);
    }

    $array2 = array(
        "tip" => $tip,
        "id" => 1,
        "notlar" => $values,
    );

    array_push($kod, $array2);
}

ogrenciadial($yil,$hafta,$og_numarasi);



ogrenciadial(1998,5,?);
  • 写回答

1条回答 默认 最新

  • duanmanmian7589 2019-06-11 08:35
    关注

    You can use explode() to turn the comma delimited string into an array.

    $og_numarasi = explode(',', $solan->description);
    

    You can then loop through the $og_numarasi array to add each as a new entry into your $values array.

    if($adi =="Turkce") {
        $tip = "DuzMantik";
        $values = array();
    
        foreach($olan->selections as $solan) {
            $og_numarasi = explode(',', $solan->description);
    
            $notum = $solan->note;
            foreach($og_numarasi as $number) {
                $ogrneci_adi = ogrenciadial($yil,$hafta,$number);
                $values[] = array("tur"=>$number,"tid"=>$ogrneci_adi,"not"=>$notum);
            }
        }
    
    
        $array2 = array(
            "tip" => $tip,
            "id" => 1,
            "notlar" => $values,
        );
    
        array_push($kod, $array2);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计