HI我對PHP相當陌生。Php Array key =>值搜索
我有一個數組
$ ARR =陣列(0 =>數組( 'GID'=> 1, '組名'=> 「CAT1」, '成員'=>數組(0 =>數組( '''')), 1 => array('GID'=> 11,'mname'=>'wwww'),1 => array('mid'=> 12,'mname'=>'wswww')) => 2, '組名'=> 「CAT2」, '成員'=>數組(0 =>數組( '中'=> 13, 'MNAME'=> 'gggwwww'),1 =>數組( '中' => 14,'mname'=>'wvvwww'))), 2 => array('GID'=> 3,'groupname'=>「cat1」,'members'=> array(0 => array '中'=> 15, 'MNAME'=> 'wwddsww')),1 =>數組( '中'=> 16, 'MNAME'=> 'wwwdddw')));
ie...,I have GID,groupname,mid(member id),mname(member name).I want to insert a new mid and mname into a group if it is already in the array ,if it is not exists then create a new subarray with these elements..I also need to check a member id(mid) is also present.........................I used the code but its not working fine............. if (!empty($evntGroup)) {
foreach ($evntGroup as $k => $group) {
if ($group['GID'] == $group_id) {
foreach($group as $j=> $mem){
if($mem['mid'] == $mem_id){
unset($evntGroup[$k]['members'][$j]['mid']);
unset($evntGroup[$k]['members'][$j]['mname']);
}
else{
$evntGroup[$k]['members'][] = array(
'mid' => $mem_id,
'mname' => $mem_name);
}}
} else {
$evntGroup[] = array(
'GID' => $group_id,
'groupname' => $Group['event_group_name'],
'members' => array(
0 => array(
'mid' => $mem_id,
'mname' => $mem_name
)
)
);
}
}
} else {
$evntGroup[$i]['GID'] = $group_id;
$evntGroup[$i]['groupname'] = $Group['event_group_name'];
$evntGroup[$i]['members'][] = array(
'mid' => $mem_id,
'mname' => $mem_name);
$i++;
}
它的'mid'是在'members'有其自己的ID ...什麼你的預期結果就像'GID'=> 1'被修改爲 – Baba