简体   繁体   English

PHP数组操作

[英]PHP array manipulation

I have the code below . 我有下面的代码。 it looks for the case and creates an array of rows and columns. 它查找情况,并创建一个由行和列组成的数组。 $pv->results[$row1][1][0] actually is $pv->result->[rownumber][coulmnnumber][0] . $pv->results[$row1][1][0]实际上是$pv->result->[rownumber][coulmnnumber][0] Now this is for only 2 columns as you can see. 现在,您只能看到两列。 However I want an array like $myArr = array(0=>1, 1=>7, 2=>8, 3=>9 ) to be added below for column. 但是我想在下面为列添加像$myArr = array(0=>1, 1=>7, 2=>8, 3=>9 )这样的数组。 What it is doing, is adding 4 columns (0,1,2,3) into the code below. 它正在做的是在下面的代码中添加4列(0,1,2,3)。 So now I will have 4 cases instead of 2 cases as I need to more columns. 所以现在我将有4个案例,而不是2个案例,因为我需要更多列。 Also the case value will not be 1 and 2, it will be 1, 7, 8 and 9 respectively. 同样,case值将不是1和2,分别是1、7、8和9。 How can I do that? 我怎样才能做到这一点? Thanks. 谢谢。

for($i=0;$i<count($pv->rawData); $i++){ 
SWITCH ($pv->rawData[$i]->my ID){
         CASE '1':
          $row1++;
          $pv->results[$row1][1][0] =  $pv->rawData[$i]->data;

           break;

        CASE '2':
          $row2++;
         $pv->results[$row2][2][0] =  $pv->rawData[$i]->data;

          break;    
}       

i think you're looking for this; 我认为您正在寻找这个;

$idField = 'my ID';
foreach( $pv -> rawData as $data ) $pv -> results[ ++${ 'row' . $data -> $idField } ][ $data -> $idField ][ 0 ] = $data -> data;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM