0
<?php
$td = date("d");

for ($i = 1; $i <= $td; $i++)
{
  $num18 = count($this->numbermonth18);
  echo "['1'," . $num18 . "],";
}

The above code will display the output like, ['1',12],['1',12],['1',12],['1',12],['1',12],['1',12],['1',12],['1',12],['1',12],['1',12],['1',12],['1',12],['1',12],['1',12],['1',12],['1',12],['1',12],['1',12],['1',12],['1',12],['1',12],['1',12],['1',12],['1',12],['1',12],['1',12],['1',12],['1',12],['1',12],['1',12],.

I need to replace the 18 with $i value in the above code. How can I use $i instead of 18 in the for loop to display all the values of $this->numbermonth1, $this->numbermonth2, $this->numbermonth3 etc. and print the array?

4

1 回答 1

4

你可以这样做:

for($i=1;$i<=$td;$i++)
{
  $num=count($this->{'numbermonth'.$i});
  echo "['1',".$num."],";
}
于 2013-04-30T01:39:16.983 回答