duan0821
duan0821
2017-06-22 10:37

如何在php中将数组值从一个函数传递给另一个函数?

已采纳

I am selecting multiple Id from Page1 and sending to Page2 which is working, Now I have to display all id to function name fake_user_archive for delete. I am getting empty value in the function.

Example: I have id no 1,5,20,50. I selected from Page1 and sending that id to page2. My code will check the email status if the status is 1 it will call the next function which is called as fake_user_archive and there email will delete. but I am not getting any value inside the function. page1.php

This is not my whole code. only for reference.

<?php
while ($stmt->fetch()) {
    echo"<input type='checkbox' name='check_list[]' value='".$id."'>";
}?>

Page2.php

    switch($_GET['function']) {
    case 'checking':checking($conn);break;
    default : redirect('index.php');
    }
    function checking($conn)
    {
    // loop over checked checkboxes
    foreach($_POST['check_list'] as $checkbox) {

        //echo $checkbox;//displaying all id
        $sql_all="SELECT * FROM `request` WHERE Id='".$checkbox."'";
        $result_chk=$conn->query($sql_all);
           if (isset($result_chk->num_rows) > 0) {
               while($row = $result_chk->fetch_assoc()) {
                    $r_email_verify=$row['email_verification'];

               }
           }

           if ($r_email_verify == 1) {
              fake_user_archive($conn);//calling the function but getting empty
           }
else{
other_function();
}

    }//foreach

    }

    function fake_user_archive($conn)
    {
        // how do i get here all my id which is selected from page1.php
        //deactive id here
    }
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • dongzhong8691 dongzhong8691 4年前

    1st : you can pass N number of parameter to function pass it like this

    fake_user_archive($conn,$checkbox);
    

    2nd : function should be

    function fake_user_archive($conn,$checkbox)
    {
       var_dump($checkbox);
    }
    
    点赞 评论 复制链接分享

相关推荐