开发者

Generate multiple dimension array in CodeIgniter

开发者 https://www.devze.com 2023-03-22 23:54 出处:网络
By using the code below in CodeIgniter, we can generate a table as below $this->load->library(\'table\');

By using the code below in CodeIgniter, we can generate a table as below

$this->load->library('table');

$data = array(
             array('11', '12', '13'),
             array('21', '22', '23'),
             array('31', '32', '33'),
             array('41', '42', '43')    
           开发者_JS百科  );

echo $this->table->generate($data);

Output:

Generate multiple dimension array in CodeIgniter

I want to ask how can I put this array in for loop likes:

for ($x = 0; $x < 5; $x++) {
    for ($y = 0; $y < 4; $y++) {
        $data xxx;
    }
}

What is the code to replace in xxx?

Thanks


Maybe:

$data= array();
for ($x = 1; $x < 5; $x++) {
    $data[$x]= array(); 
    for ($y = 1; $y < 4; $y++) {
        $data[$x][]= ($x*10)+($y);
    }
}
echo "<pre>";
print_r($data);


Here is how I would enumerate the array:

foreach ($data as $row) {
    foreach ($row as $cell) {
        echo $cell;
        // Do stuff here!
    }
}

If you need the index of each row / column you can use the following variant:

foreach ($data as $row_index => $row) {
    foreach ($row as $column_index => $cell) {
        // Stuff!
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消