0

我找不到循环这种数组结构的方法。有谁遇到过。?

print_r 输出

Array ( 
        [0] => Array ( [0] => [LABOR_NO] => [1] => 3 [WORK_CODE] => 3 [2] => [MHR] => [3] => [PHR] => [4] => [PESO_VALUE] => ) 
        [1] => Array ( [0] => [LABOR_NO] => [1] => 3 [WORK_CODE] => 3 [2] => [MHR] => [3] => [PHR] => [4] => [PESO_VALUE] => ) 
        [2] => Array ( [0] => 1 [LABOR_NO] => 1 [1] => 3 [WORK_CODE] => 3 [2] => 2.50 [MHR] => 2.50 [3] => 0.00 [PHR] => 0.00 [4] => 3000.00 [PESO_VALUE] => 3000.00 ) 
      )

转储输出

array(3) { 
        [0]=> array(10) { 
                        [0]=> NULL ["LABOR_NO"]=> NULL [1]=> string(1) "3" ["WORK_CODE"]=> string(1) "3" [2]=> NULL ["MHR"]=> NULL [3]=> NULL ["PHR"]=> NULL [4]=> NULL ["PESO_VALUE"]=> NULL } 
        [1]=> array(10) { [0]=> NULL ["LABOR_NO"]=> NULL [1]=> string(1) "3" ["WORK_CODE"]=> string(1) "3" [2]=> NULL ["MHR"]=> NULL [3]=> NULL ["PHR"]=> NULL [4]=> NULL ["PESO_VALUE"]=> NULL } 
        [2]=> array(10) { [0]=> string(1) "1" ["LABOR_NO"]=> string(1) "1" [1]=> string(1) "3" ["WORK_CODE"]=> string(1) "3" [2]=> string(4) "2.50" ["MHR"]=> string(4) "2.50" [3]=> string(4) "0.00" ["PHR"]=> string(4) "0.00" [4]=> string(7) "3000.00" ["PESO_VALUE"]=> string(7) "3000.00" }
        }    

这是我所做的,但我认为没有工作。我不知道=>一直持续到每个把他们变成$keys..

include('MySQLHandler.php');
class Displayer  extends MySQLHandler {

    public function getTitle($batchNo = NULL,$workCode = NULL){
        $this->init();
        $STMT="SELECT REC_NO,PARTS_WORKSCOPE FROM RAPID_TEMP_ESTIMATE_V3 WHERE BATCH_NO={$batchNo} AND WORK_CODE={$workCode} AND PARTS_WORKSCOPE_TYPE='Workscope:'";
        $DATA=$this->Select($STMT);

        // create array of data subjects..
        $result = array();
        $result['REC_NO'] = $DATA[0]['REC_NO'];
        $result['PARTS_WORKSCOPE'] = $DATA[0]['PARTS_WORKSCOPE'];

        return $result;
    }

    public function getTotal($batchNo = NULL,$workCode = NULL){
        $this->init();

        // par selection
        $STMT="SELECT PAR_VALUE FROM RAPID_PAR WHERE PAR_NAME='LABOR_RATE_PER_HOUR'";
        $DATA = $this->Select($STMT);
        $PAR_VALUE = $DATA[0]['PAR_VALUE'];

        // rollup
        $STMT="SELECT LABOR_NO,WORK_CODE,MHR,PHR,PESO_VALUE FROM RAPID_TEMP_ESTIMATE_V3 WHERE BATCH_NO={$batchNo} AND WORK_CODE={$workCode} ORDER BY MINOR_WORK_CODE, WORK_CODE_ORDER";
        $DATA=$this->Select($STMT);

        foreach($DATA as $key=>$value){
                foreach($value as $fieldset=>$values){
                    echo $fieldset.'<br/>';
                }
            }
    }
}

$displayer = new Displayer;

$displayer->getTotal(18,3);
4

0 回答 0