내가 뭘하려고하는지 모르겠습니다. 잘못된 이름을 사용했다면 사과드립니다.PHP 다차원 배열 - 작동시키기
는 여기에 내가 달성하기 위해 노력하고 무엇의 기본적인 예입니다
여기$arrayData = (4,5,6,7,8,9,10);
$public function setArray($colNum){
$i = 0;
while($i < count($arrayData){
내가 무엇을 해야할지하지 않는 곳입니다. $ colNum이 새 배열의 열 수를 설정하도록합니다. 그래서
if $colNum = 4, then $arrayNew[$i][$i][$i][$arrayData[$i]
이 설정됩니다. 현재 각기 다른 수의 열을 처리하고 작동하는 여러 함수를 만들었지 만 2 열에서 30 열의 범위를 가질 수 있으며 더 효율적으로 수행 할 수있는 방법이 있다는 것을 알고 있습니다.
가 여기에 4 열 테이블의 작업 예제 난 당신이 뭘 하려는지 얻을 확실하지 않다
public function parseTable($tableHeader,$isMoney,$colNum) {
$tableData = $this->myArray;
$count = 0;
$placeHolder = 0;
while($count < count($tableData)){
// This hides the column headers
if($count > $colNum - 1) {
$col1Array[$placeHolder] = $tableData[$count];
$col2Array[$placeHolder] = $tableData[$count + 1];
$col3Array[$placeHolder] = $tableData[$count + 2];
$col4Array[$placeHolder] = $tableData[$count + 3];
$placeHolder ++;
}
$count = $count + $colNum;
}
// Remove the empty lines from the array
$col1Array = array_values(array_filter($col1Array));
$col2Array = array_values(array_filter($col2Array));
$col3Array = array_values(array_filter($col3Array));
$col4Array = array_values(array_filter($col4Array));
// Put the 0 back in the array
$col1Array = array_values(str_replace('~',0,$col1Array));
$col2Array = array_values(str_replace('~',0,$col2Array));
$col3Array = array_values(str_replace('~',0,$col3Array));
$col4Array = array_values(str_replace('~',0,$col4Array));
$count = 0;
$tableHTML = "<table class=\"table table-striped table-hover\" data-toggle=\"table\"
data-search=\"true\"
data-show-columns=\"true\"
data-pagination=\"true\"
>
<thead>
<tr>
<th>$tableHeader[0]</th>
<th>$tableHeader[1]</th>
<th>$tableHeader[2]</th>
<th>$tableHeader[3]</th>
</tr>
</thead>
<tbody>";
while($count < count($col1Array)){
// Replaces empty values with the text set when calling the function
if($col1Array[$count] == ""){
$col1Array[$count] = $emptyResult;
}
if($col2Array[$count] == ""){
$col2Array[$count] = $emptyResult2;
}
if($col3Array[$count] == ""){
$col3Array[$count] = $emptyResult3;
}
if($col4Array[$count] == ""){
$col4Array[$count] = $emptyResult4;
}
// Converts data into money if specified in the function
if($isMoney[0] == "Currency"){
if($col1Array != '0'){$colOne = money_format('%.2n', $col1Array[$count]);}
else{$col1Array = "$0.00";}
}else{$colOne = str_replace('0.00','0',$col1Array[$count]);}
if($isMoney[1] == "Currency"){
if($col2Array != '0'){$colTwo = money_format('%.2n', $col2Array[$count]);}
else{$colTwo = "$0.00";}
}else{$colTwo = str_replace('0.00','0',$col2Array[$count]);}
if($isMoney[2] == "Currency"){
if($col3Array != '0'){$colThree = money_format('%.2n', $col3Array[$count]);}
else{$colThree = "$0.00";}
}else{$colThree = str_replace('0.00','0',$col3Array[$count]);}
if($isMoney[3] == "Currency"){
if($col4Array != '0'){$colFour = money_format('%.2n', $col4Array[$count]);}
else{$colFour = "$0.00";}
}else{$colFour = str_replace('0.00','0',$col4Array[$count]);}
$tableHTML = $tableHTML . "
<tr>
<td>$colOne</td>
<td>$colTwo</td>
<td>$colThree</td>
<td>$colFour</td>
</tr>";
$count++;
}
$tableHTML = $tableHTML . "
</tbody>
</table>";
$this->tableHTML = $tableHTML;
$this->col1Array = $col1Array;
$this->col2Array = $col2Array;
$this->col3Array = $col3Array;
$this->col4Array = $col4Array;
$this->totalRows = count($this->col1Array);
}
n 시간 동안 자신의 자식에게 배열을 추가하는 재귀 함수를 사용 했습니까? 그 후 데이터를 추가 – UnskilledFreak
나는 재귀 함수를 사용하는 것에 대해 생각조차하지 않았지만 array_push를 사용하면 내 문제에 대한 훌륭한 해결책입니다. – zadees
원하는 것을 이해하는 데 어려움을 겪고 있습니다. '$ colNum'은 실제로 열의 수입니까? 치수의 개수 인 것 같습니다. – Barmar