关于PHP数组迭代器的使用方法实例

2022-04-15 12:33:10

近来在开发一个视力筛查电子报告系统的产品,这个产品的作用是自动提取视力筛查过程中得到的屈光检查数据,并结合数据自动生成通俗易懂且专业的电子报告,以方便家长可以通过公众号或H5链接查阅。

要实现这个需求,第一步是对验光设备里打印出来的纸质报告做OCR,图片识别接口返回的是二维数组,报告的原图是这样的:

关于PHP数组迭代器的使用方法实例

OCR接口返回的数据是这样的

array(3) {  ["words_result"]=>  array(36) {    [0]=>    array(1) {      ["words"]=>      string(8) "FA-6000A"    }    [1]=>    array(1) {      ["words"]=>      string(10) "2022-09-16"    }    [2]=>    array(1) {      ["words"]=>      string(7) "04:00"    }    [3]=>    array(1) {      ["words"]=>      string(8) "SHOP:B"    }    [4]=>    array(1) {      ["words"]=>      string(7) "NAME:"    }    [5]=>    array(1) {      ["words"]=>      string(3) "<R>"    }    [6]=>    array(1) {      ["words"]=>      string(1) "C"    }    [7]=>    array(1) {      ["words"]=>      string(1) "A"    }    [8]=>    array(1) {      ["words"]=>      string(5) "-1.50"    }    [9]=>    array(1) {      ["words"]=>      string(5) "-0.25"    }    [10]=>    array(1) {      ["words"]=>      string(3) "131"    }    [11]=>    array(1) {      ["words"]=>      string(5) "-1.50"    }    [12]=>    array(1) {      ["words"]=>      string(7) "-0,25"    }    [13]=>    array(1) {      ["words"]=>      string(3) "122"    }    [14]=>    array(1) {      ["words"]=>      string(7) "-1,50"    }    [15]=>    array(1) {      ["words"]=>      string(7) "-0,25"    }    [16]=>    array(1) {      ["words"]=>      string(3) "114"    }    [17]=>    array(1) {      ["words"]=>      string(5) "-1.50"    }    [18]=>    array(1) {      ["words"]=>      string(7) "-0,25"    }    [19]=>    array(1) {      ["words"]=>  words']));       $wordsResult->next();       array_push($usefulNumList, $this->getCleanNum($wordsResult->current()['words']));    }}

需注意的地方请看一下代码注释,本身封装得很好,很容易理解和调用的

相关文章 大家在看