I need to store an array in this format
array(2)
{
[1002] => array(2)
{
[0] => string(1) "2"
[1] => string(1) "1"
}
}
So far i only have this:
function permissions($conn){
$sql="SELECT PROCESS,PERMISSION FROM table WHERE PROCESS=1002";
$result = $conn->executeSQL($sql);
$return = array();
foreach($result as $value){
array_push($return,$value['PROCESS_ID'],$value['PERMISSION_ID']);
}
which brings: I don´t know how to make this array multidimensional, i don't want the "1002" to repeat
array(2)
{
[0] => string(4) "1002"
[1] => string(1) "2"
[2] => string(4) "1002"
[3] => string(1) "1"
}
Hi try something like this:
function permissions($conn){
$sql="SELECT PROCESS,PERMISSION FROM table WHERE PROCESS=1002";
$result = $conn->executeSQL($sql);
$return = array();
foreach($result as $value){
if(!isset($return[$value['PROCESS_ID']])){
$return[$value['PROCESS_ID']] = [];
}
$return[$value['PROCESS_ID']][] = $value['PERMISSION_ID'];
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.