【发布时间】:2021-11-04 04:22:29
【问题描述】:
我有一个非常简单的数组,但有一些重复的条目。 我只想在每个重复项的末尾打印 cmets 列。我正在使用 php 框架 codeigniter v3。
请看下表结构:
下面是我迄今为止尝试过的代码,但它在第一项的开头打印。
$Test_Comments = "";
foreach($result as $value)
{
if ($Test_Comments != $value['Test_Comments'])
{
echo $value['Test_Comments'];
}
$Test_Comments = $value['Test_Comments'];
}
编辑:
var_export($result);
array (
0 =>
array (
'ID' => '570',
'Patient_ID' => '4558',
'Test_ID' => '570',
'Test_Status' => 'Performed',
'Head_ID' => '4769',
'Result_Value' => 'Negative',
'Test_Name' => 'Viral Marker ',
'Test_Comments' => '<p><strong><em>Comments:</em></strong></p>
<p><em>Anti HCV,HbsAg were performed by immunochoromatographic Screeing Method. The Technique has Sensitivity of 99% and Sepcifity of 98% .Clinically inconsistent result should be reconfrimed by alternative method e.g (ELISA,PCR)</em></p>',
),
1 =>
array (
'ID' => '570',
'Patient_ID' => '4558',
'Test_ID' => '570',
'Test_Status' => 'Performed',
'Head_ID' => '4769',
'Result_Value' => 'Negative',
'Test_Name' => 'Viral Marker ',
'Test_Comments' => '<p><strong><em>Comments:</em></strong></p>
<p><em>Anti HCV,HbsAg were performed by immunochoromatographic Screeing Method. The Technique has Sensitivity of 99% and Sepcifity of 98% .Clinically inconsistent result should be reconfrimed by alternative method e.g (ELISA,PCR)</em></p>',
),
2 =>
array (
'ID' => '464',
'Patient_ID' => '4558',
'Test_ID' => '464',
'Test_Status' => 'Performed',
'Head_ID' => '4769',
'Result_Value' => '76',
'Test_Name' => 'Random Sugar',
'Test_Comments' => '',
),
3 =>
array (
'ID' => '340',
'Patient_ID' => '4558',
'Test_ID' => '340',
'Test_Status' => 'Performed',
'Head_ID' => '4769',
'Result_Value' => '0.7',
'Test_Name' => 'LFT-Liver Functions Tests',
'Test_Comments' => '',
),
4 =>
array (
'ID' => '340',
'Patient_ID' => '4558',
'Test_ID' => '340',
'Test_Status' => 'Performed',
'Head_ID' => '4769',
'Result_Value' => '0.5',
'Test_Name' => 'LFT-Liver Functions Tests',
'Test_Comments' => '',
),
5 =>
array (
'ID' => '340',
'Patient_ID' => '4558',
'Test_ID' => '340',
'Test_Status' => 'Performed',
'Head_ID' => '4769',
'Result_Value' => '0.2',
'Test_Name' => 'LFT-Liver Functions Tests',
'Test_Comments' => '',
),
6 =>
array (
'ID' => '340',
'Patient_ID' => '4558',
'Test_ID' => '340',
'Test_Status' => 'Performed',
'Head_ID' => '4769',
'Result_Value' => '29',
'Test_Name' => 'LFT-Liver Functions Tests',
'Test_Comments' => '',
),
7 =>
array (
'ID' => '340',
'Patient_ID' => '4558',
'Test_ID' => '340',
'Test_Status' => 'Performed',
'Head_ID' => '4769',
'Result_Value' => '32',
'Test_Name' => 'LFT-Liver Functions Tests',
'Test_Comments' => '',
),
8 =>
array (
'ID' => '340',
'Patient_ID' => '4558',
'Test_ID' => '340',
'Test_Status' => 'Performed',
'Head_ID' => '4769',
'Result_Value' => '164',
'Test_Name' => 'LFT-Liver Functions Tests',
'Test_Comments' => '',
),
9 =>
array (
'ID' => '124',
'Patient_ID' => '4558',
'Test_ID' => '124',
'Test_Status' => 'Performed',
'Head_ID' => '4769',
'Result_Value' => '0.7',
'Test_Name' => 'RFT-Renal Function Tests',
'Test_Comments' => '',
),
10 =>
array (
'ID' => '124',
'Patient_ID' => '4558',
'Test_ID' => '124',
'Test_Status' => 'Performed',
'Head_ID' => '4769',
'Result_Value' => '23',
'Test_Name' => 'RFT-Renal Function Tests',
'Test_Comments' => '',
),
)
【问题讨论】:
-
你能显示你的数组的
var_export()吗? -
$value['Test_Comments ']!==$value['Test_Comments']注意尾随空格 -
@nice_dev 问题已更新。请参阅编辑
-
嗯,它可能与大多数
'Test_Comments' => '',有关 -
@RiggsFolly 不是所有的测试都有 cmets,只有少数有 cmets,你可以忽略空的 cmets
标签: php codeigniter foreach codeigniter-2