使用PHP递增数组中的数组值


Incrementing the array value within an array using PHP

所以我的最终结果是这样的(最终结果将有48个条目):

$theArray=array(
$theArray1,
$theArray2,
$theArray3,
$theArray4,
$theArray5,
$theArray6
);

我已经尝试了一些事情,但我认为这是最接近的,但我还没有做到,任何帮助都很感激。

$i = 0;
while ($i <= 48){
  $theArray[]=${"theArray".$i.","}
  $i++
 }
$theArray[]=${"theArray".$i};

您错过了;在行的末尾:

$i = 0;
while ($i <= 48){
  $theArray[]=${"theArray".$i.","}; // missed ; here
  $i++; // missed ; here
 }
$theArray[]=${"theArray".$i};

您必须使用函数compact来创建包含变量的数组。试着阅读文档http://php.net/manual/en/function.compact.php

下面是一些例子http://www.w3schools.com/php/func_array_compact.asp

保持简单如下:

<?php
$i = 0;
$theArray = array();
while ($i <= 48){
  array_push($theArray, '$theArray'.$i);
  $i++;
 }
echo '$arr = array('.implode(',', $theArray).');';
?>

就在你这边跑吧。干杯