dp7311 2015-02-26 11:26
浏览 47

如何仅比较存储在数组中的行中的某些单元格

Got a strange situation and I don't know how to figure it out. Let's see if you can give me a hint!

I've built an array with rows in his content like this and want to delete duplicates:

echo $nodup_filter[1];

<tr>
<td>29/06/2015</td>
<td>09:00</td>
<td>29/06/2015</td>
<td>12:00</td>
<td>3</td>
<td>code 1</td>
<td>1007 Additional information 5</td>
<td>109 Additional information 6</td>
<td>Additional information 7</td>
<td>Additional information 8</td>
<td> </td>
</tr>

echo $nodup_filter[2];

<tr>
<td>12/02/2015</td>
<td>16:00</td>
<td>14/04/2015</td>
<td>18:00</td>
<td>2</td>
<td>Code 2</td>
<td>Additional information 1</td>
<td>Additional information 2</td>
<td>Additional information 3</td>
<td>Additional information 4</td>
<td> </td>
</tr>

echo $nodup_filter[3];

 <tr>
<td>29/06/2015</td>
<td>09:00</td>
<td>29/06/2015</td>
<td>12:00</td>
<td>3</td>
<td>code 1</td>
<td>1007 Additional information 5</td>
<td>109 Additional information 6</td>
<td>Additional information 7</td>
<td>Additional information 8</td>
<td> </td>
</tr>

And so on and so forth...

What I want is to compare the entire array, but only from the sixth cell to the end of every array position.

I want to compare this:

<td>code 1</td>
<td>1007 Additional information 5</td>
<td>109 Additional information 6</td>
<td>Additional information 7</td>
<td>Additional information 8</td>
<td> </td>

With this:

<td>Code 2</td>
<td>Additional information 1</td>
<td>Additional information 2</td>
<td>Additional information 3</td>
<td>Additional information 4</td>
<td> </td>

And with this:

<td>code 1</td>
<td>1007 Additional information 5</td>
<td>109 Additional information 6</td>
<td>Additional information 7</td>
<td>Additional information 8</td>
<td> </td>

And if there is a match, delete the duplicate array position. As you can see the $nodup_filter[1]; and $nodup_filter[3]; got the same information from his sixth cell to the end of the row, so one of them ($nodup_filter[1] or $nodup_filter[3]) need to be deleted. And then, continue compairing with the next array position..

Beforehand, thanks a lot for your help and time.

  • 写回答

1条回答 默认 最新

  • dongyuan7981 2015-02-26 12:49
    关注

    Since you have it in array you can loop and check the content of only from the sixth cell text, one way to doing this will be this

    $unique_array = array();
    foreach($data as $k=>$v) {
       // assuming $data[$k][6] sixth cell
       if( in_array($data[$k][6], $unique_array) ) { 
          //remove duplicate 
          unset($data[$k]);
       }else {
         //Push it to final array 
         array_push($unique_array, $v);
       }
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化怎样画共定位分析图
  • ¥18 模拟电路问题解答有偿速度
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址
  • ¥15 elmos524.33 eeprom的读写问题