I have an array like this:
我有一个像这样的数组:
pnotifyArr[] = array(
"type" => "New ".$RowP[0]."</br>",
"title" => "<a href=\"/sys/mailbox/MailInbox.php?ID=$RowP[3]$rid\" onclick=\"javascript:update_status('$RefID')\" target=\"_blank\">".$TitleForShow."</a></br>",
"AssignedBy" => "From: ".trim($RowP[2]).".",
"RefID"=>$RefID,
"Status"=>$Status,
"Notice_type" => $TypeN,
"Notice_title" => $TitleForShow,
"Notice_AssignedBy" => $RowP[2]
);
which is retrieved from the database. But I need only the key values of Notice_type
and Notice_title
to be compared in all the instances.
从数据库中检索。但我只需要在所有实例中比较Notice_type和Notice_title的键值。
if(count($pnotifyArr)>0)
{
$rows = sizeof($pnotifyArr);
$columns = sizeof($pnotifyArr[0]);
//$columnkeys = array_key_exists('Notice_type',$pnotifyArr[0]);
for ($i =0; $i < $columns; $i++)
{
for ($j =0; $j < $rows; $j++)
{
for($k = $j+1; $k < $rows; $k++)
{
if( $pnotifyArr[$j][$columnkeys[$i]] == $pnotifyArr[$k][$columnkeys[$i]]) //&& ($pnotifyArr[$j][$columnkeys[$i]] == $pnotifyArr[$k][$columnkeys[$i]]) )
$pnotifyArr[$k][$columnkeys[$i]] = "";
}
}
}
}
I don't know how to get the values of these two specific keys recursively. Can anyone help me regarding this issue?
我不知道如何递归地获取这两个特定键的值。有人可以帮我解决这个问题吗?
The above code gets me all the key values any which is not required in my case.
上面的代码获取了我的所有键值,在我的情况下不需要。
Thanks a lot for spending your time.
非常感谢您花时间。
for ($i =0; $i < $columns; $i++)
{
for ($j =0; $j < $rows; $j++)
{
for($k = $j+1; $k < $rows; $k++)
{
//if( $pnotifyArr[$j][$typekeys[$i]] == $pnotifyArr[$k][$typekeys[$i]]) && ($pnotifyArr[$j][$titlekeys[$i]] == $pnotifyArr[$k][$titlekeys[$i]]) )
if( $pnotifyArr[$j]['Notice_type'] == $pnotifyArr[$k]['Notice_type'] && $pnotifyArr[$j]['Notice_title'] == $pnotifyArr[$k]['Notice_title'] )
$pnotifyArr[$k][$i] = "";
}
}
}
My output shows something like this........ as below
我的输出显示如下........如下
for ($i =0; $i < $columns; $i++)
{
for ($j =0; $j < $rows; $j++)
{
for($k = $j+1; $k < $rows; $k++)
{
//if( $pnotifyArr[$j][$typekeys[$i]] == $pnotifyArr[$k][$typekeys[$i]]) && ($pnotifyArr[$j][$titlekeys[$i]] == $pnotifyArr[$k][$titlekeys[$i]]) )
if( $pnotifyArr[$j]['Notice_type'] == $pnotifyArr[$k]['Notice_type'] && $pnotifyArr[$j]['Notice_title'] == $pnotifyArr[$k]['Notice_title'] )
{
$pnotifyArr[$k][$i] = "";
}
}
}
}
foreach ($pnotifyArr as $key => $value) {
if ($value="") {
unset($pnotifyArr[$key]);
}
}
$pnotifyArr = array_values($pnotifyArr);
Please help me.... I dont understand Whats happening here......
请帮帮我....我不明白这里发生了什么......
Output:
test:{"pnotify":[ {"type":"New Mail</br>","title":"RE: Hello</a></br>","AssignedBy":"From: SAMANTHA CHUA PEIXUAN.","RefID":"1fbc490c47ae00967623bf93f92b9262","Status":"1","Notice_type":"Mail","Notice_title":"RE: Hello","Notice_AssignedBy":"SAMANTHA CHUA PEIXUAN"},
test:{“pnotify”:[{“type”:“New Mail ”,“title”:“RE:Hello ”,“AssignedBy”:“来自:SAMANTHA CHUA PEIXUAN 。“,”RefID“:”1fbc490c47ae00967623bf93f92b9262“,”状态“:”1“,”Notice_type“:”Mail“,”Notice_title“:”RE:Hello“,”Notice_AssignedBy“:”SAMANTHA CHUA PEIXUAN“},
{"type":"New Mail</br>","title":"RE: Hello</a></br>","AssignedBy":"From: SAMANTHA CHUA PEIXUAN.","RefID":"ead077c279a7cfdf60882fcc75a8f23b","Status":"1","Notice_type":"Mail","Notice_title":"RE: Hello","Notice_AssignedBy":"SAMANTHA CHUA PEIXUAN","0":"","1":"","2":"","3":"","4":"","5":"","6":"","7":""}]}
{“type”:“New Mail ”,“title”:“RE:Hello ”,“AssignedBy”:“来自:SAMANTHA CHUA PEIXUAN。”,“RefID”:“ ead077c279a7cfdf60882fcc75a8f23b“,”状态“:”1“,”Notice_type“:”Mail“,”Notice_title“:”RE:Hello“,”Notice_AssignedBy“:”SAMANTHA CHUA PEIXUAN“,”0“:”“,”1“: “”, “2”: “”, “3”: “”, “4”: “”, “5”: “”, “6”: “”, “7”: “”}]}
3 个解决方案
#1
1
To get specific value in looping:
要在循环中获得特定值:
$pnotifyArr[$j]['Notice_type'];
$pnotifyArr[$k]['Notice_title'];
example:
foreach($pnotifyArr as $key=>$val)
{
if($pnotifyArr[$key]['Notice_type'] == $pnotifyArr[$key]['Notice_title'])
{
$pnotifyArr[$key][XXX] = '';
}
}
To Remove Empty Key:
要删除空键:
foreach($pnotifyArr as $key=>$val)
{
if($pnotifyArr[$key]['Notice_type'] == $pnotifyArr[$key]['Notice_title'])
{
$pnotifyArr[$key][XXX] = '';
}
if (is_null($val))
{
unset($pnotifyArr[$key]);
}
}
Then try print_r print_r($pnotifyArr);
然后尝试print_r print_r($ pnotifyArr);
#2
1
function array_uniquecolumn($arr) { $temp_array = array(); $temp_array1 = array(); $final_array = array();
function array_uniquecolumn($ arr){$ temp_array = array(); $ temp_array1 = array(); $ final_array = array();
foreach ($arr as $key => $value) {
$temp_array[] = $value["Notice_type"].$value["Notice_title"];
}
//print_r ($temp_array);
$temp_array = array_unique($temp_array);
$temp_array1 = array_keys($temp_array);
//print_r ($temp_array1);
foreach ($temp_array1 as $key => $value) {
$final_array[] = $arr[$value];
}
return ($final_array);
}
//print_r( array_uniquecolumn($pnotifyArr));
I get perfect result from this function......
我从这个功能中得到了完美的结果......
#3
0
foreach($pnotifyArr as $child_array) {
echo $child_array['Notice_type'];
echo $child_array['Notice_title'];
}
#1
1
To get specific value in looping:
要在循环中获得特定值:
$pnotifyArr[$j]['Notice_type'];
$pnotifyArr[$k]['Notice_title'];
example:
foreach($pnotifyArr as $key=>$val)
{
if($pnotifyArr[$key]['Notice_type'] == $pnotifyArr[$key]['Notice_title'])
{
$pnotifyArr[$key][XXX] = '';
}
}
To Remove Empty Key:
要删除空键:
foreach($pnotifyArr as $key=>$val)
{
if($pnotifyArr[$key]['Notice_type'] == $pnotifyArr[$key]['Notice_title'])
{
$pnotifyArr[$key][XXX] = '';
}
if (is_null($val))
{
unset($pnotifyArr[$key]);
}
}
Then try print_r print_r($pnotifyArr);
然后尝试print_r print_r($ pnotifyArr);
#2
1
function array_uniquecolumn($arr) { $temp_array = array(); $temp_array1 = array(); $final_array = array();
function array_uniquecolumn($ arr){$ temp_array = array(); $ temp_array1 = array(); $ final_array = array();
foreach ($arr as $key => $value) {
$temp_array[] = $value["Notice_type"].$value["Notice_title"];
}
//print_r ($temp_array);
$temp_array = array_unique($temp_array);
$temp_array1 = array_keys($temp_array);
//print_r ($temp_array1);
foreach ($temp_array1 as $key => $value) {
$final_array[] = $arr[$value];
}
return ($final_array);
}
//print_r( array_uniquecolumn($pnotifyArr));
I get perfect result from this function......
我从这个功能中得到了完美的结果......
#3
0
foreach($pnotifyArr as $child_array) {
echo $child_array['Notice_type'];
echo $child_array['Notice_title'];
}