idssphp在foreach中复制数组

[英]idssphp duping array in a foreach


OK...

your answer is fine @Random, however it's still duping the ids, so i integrated your code to my dev code... so here's my final code....

你的答案很好@Random,但它仍然重复了ID,所以我将你的代码集成到我的开发代码中...所以这是我的最终代码....

$gr = mysql_query("select id from permission_sets");
$permission_arr = array(
'start_perms'  => isset($_POST['START_'.$id]),
'reply_perms'  => isset($_POST['REPLY_'.$id]),
'read_perms'   => isset($_POST['READ_'.$id]),
'upload_perms' => isset($_POST['UPLOAD_'.$id]),
'show_perms'   => isset($_POST['SHOW_'.$id]),
'download_perms' => isset($_POST['DOWNLOAD_'.$id]));

// saving the beginning of the line : "group: 1,2,3"
$header = 'PID: ';
$read   = "";
$reply  = "";
$start  = "";
$upload = "";
$download = "";
$show   = "";
$subPIDs = "";
while($row = mysql_fetch_array($gr)){
foreach($row as $pid){
//-----------------------------
// Get perm id and set it..
//-----------------------------
$pid = $pid.",";


if($permission_arr['start_perms'] == 1){
$start .= $pid;
$subPIDs .= $start;
}
if($permission_arr['read_perms'] == 1){
$read .= $pid;
$subPIDs .= $read;
}
if($permission_arr['reply_perms'] == 1){
$reply .= $pid;
$subPIDs .= $reply;
}
if($permission_arr['upload_perms'] == 1){
$upload .= $pid;
$subPIDs .= $upload;
}
if($permission_arr['download_perms'] == 1){
$download .= $pid;
$subPIDs .= $download;
}
if($permission_arr['show_perms'] == 1){
$show .= $pid;
$subPIDs .= $show;
}
$header .= $subPIDs;
}

} // End while

//------------------------------------
// Store the data in a new array..
//------------------------------------
$perm_arr = array(
'start_perms'  => $start,
'reply_perms'  => $reply,
'read_perms'   => $read,
'upload_perms' => $upload,
'show_perms'   => $show,
'download_perms' => $download);
$head = $header.' = ';
foreach($perm_arr as $key => $val){
if($val){
$head .= $key.'<br>'.$head;
}
}

print $head;
echo '<pre>';
print_r($perm_arr);

this does everything yours does... we just need to stop dupes in the output, in the array is no dupe, only in output... also when i mark only 1 box ihe array gets all or no ids...

这样做你的一切都做了...我们只需要在输出中停止欺骗,在数组中没有欺骗,只在输出中......当我只标记1个盒子时,阵列得到全部或没有ID ...

1 个解决方案

#1


try this :

试试这个 :

// list of permissions with boolean
$permission_arr = array(
    'start_perms'  => isset($_POST['START_'.$id]),
    'reply_perms'  => isset($_POST['REPLY_'.$id]),
    'read_perms'   => isset($_POST['READ_'.$id]),
    'upload_perms' => isset($_POST['UPLOAD_'.$id]),
    'show_perms'   => isset($_POST['SHOW_'.$id]),
    'download_perms' => isset($_POST['DOWNLOAD_'.$id]));

echo 'sql';
$gr = mysql_query("select id from permission_sets");
// saving the beginning of the line : "group: 1,2,3"
$header = 'group: ';
$separator = '';
while($row = mysql_fetch_array($gr)) {
    foreach($row as $g){
        $header .= $separator.$g;
        $separator = ',';
    }
}
$header = $header.' = ';
foreach($permission_arr as $k => $p){
    if($p) {
        // the permission is OK, we print this permission
        // output like "group: 1,2,3 = start_perms, <br>"
        print $header.$k.", <br>";
    }
}
智能推荐

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.itdaan.com/blog/2015/05/13/7203c16201534d4dcd652b0c40cc25d3.html



 
© 2014-2019 ITdaan.com 粤ICP备14056181号  

赞助商广告