Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.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 - Fatal编程技术网

Php 如何在会话中传递两个数组并将其组合以显示

Php 如何在会话中传递两个数组并将其组合以显示,php,Php,我正在尝试通过会话发送两个数组,然后将它们组合在一起显示,但没有显示任何内容。这是我的代码---> 我用自定义的东西替换了查询输出,这段代码适合我 <?php session_start(); function tee($uid){ include 'connect.php'; $parent=array(); $child=array(); $_SESSION["child"]=a

我正在尝试通过会话发送两个数组,然后将它们组合在一起显示,但没有显示任何内容。这是我的代码--->


我用自定义的东西替换了查询输出,这段代码适合我

  <?php
      session_start();
      function tee($uid){
          include 'connect.php';
          $parent=array();
          $child=array();
          $_SESSION["child"]=array();
          $_SESSION["parent"]=array();
          $sql="select id from relation2 where parentID=$uid";
          $result=mysqli_query($sql,$link);
          while($row=mysqli_fetch_assoc($result))
          {

            $_SESSION["child"][]=$row["id"];
            $_SESSION["parent"][]=$uid;
          }
      tee(2);

    foreach(array_combine($_SESSION["child"],$_SESSION["parent"]) as $child=>$parent)
    {
      echo $child.'----------->'.$parent;
      echo '<br>';
    }

    ?>

同时检查功能


如果您从用户输入使用中传递
$uid
,您能解释一下您想要实现什么吗?为什么需要合并它们?有几个问题,
包括“connect.php” $UID < /代码>是一个很大的安全问题,也请考虑使用<代码> mySqLI>代码>,而不是<代码> MySQL < /Cord>,它具有许多伟大的特性和安全性增强。最后,不需要有两个会话数组,一个就足够了,可以在递归函数期间填充。
  <?php
      session_start();
      function tee($uid){
          include 'connect.php';
          $parent=array();
          $child=array();
          $_SESSION["child"]=array();
          $_SESSION["parent"]=array();
          $sql="select id from relation2 where parentID=$uid";
          $result=mysqli_query($sql,$link);
          while($row=mysqli_fetch_assoc($result))
          {

            $_SESSION["child"][]=$row["id"];
            $_SESSION["parent"][]=$uid;
          }
      tee(2);

    foreach(array_combine($_SESSION["child"],$_SESSION["parent"]) as $child=>$parent)
    {
      echo $child.'----------->'.$parent;
      echo '<br>';
    }

    ?>