php 数组未在 class 构造函数中正确接收

php array not received correctly in class constructor

我正在尝试将数组传递给 class 构造函数,但出于某种原因,构造函数接收到的数组与我发送的数组不同。 构建 2 个数组并发送它们的代码:

$exportArray=array();
            foreach($new->arr as $ar){
                $values[]=intval($ar[4]);
                $dates[]=strtotime($ar[1]);
                $exportArray[]=array($ar[5],$ar[0],$ar[2],$ar[3],$ar[1]);
            }
            $new->query="SELECT distinct c_name,date,m_name,t_amount,t_id FROM transport,customer,driver,material WHERE"
                    . " customer.c_id=transport.c_id AND material.m_id=transport.m_id AND transport.d_id=$name ORDER BY date DESC LIMIT $lim";
            //var_dump($new->query);
            $new->again();
            foreach($new->arr as $ar){
                echo "<tr><td><a href='customers.php?c_name=$ar[0]'>$ar[0]</a></td><td>$ar[1]</td><td><a href='materials.php?m_name=$ar[2]'>$ar[2]</a></td><td>$ar[3]</tr>";
                //var_dump($ar);
            }
            ?>
        </table>
  <?php
    if(isset($lim)&&$lim!="1"){
        $qr=new query("SELECT last FROM graph");
        $last=$qr->arr[0][0];
            var_dump($values);
            var_dump($dates);
        $graph1=new graphs($dates,$values,"Deliveries With Respect To Dates","driver");
        $graph1->getGraph("date");
        $qr->again();

class 构造函数接收它们并执行检查:

class graphs{

    public $xtype=NULL;
    public $ytype=NULL;
    public $graph=NULL;
    private $xs=array();
    private $ys=array();
    public $type=NULL;

    public function __construct($arr1,$arr2,$title,$type){
        if(!is_array($arr1)||!is_array($arr2)){
            die("in order to see the graph, you need more than one result!");
        }
        elseif(count($arr1)<=1||count($arr2)<=1){
            var_dump($arr1);
            var_dump($arr2);
            die("in order to see the RELEVANT graph, you need more than one result!");
        }
        $this->title=$title;
        $this->xs=$arr1;
        $this->ys=$arr2;
        $this->graph= new Graph(600,400,'auto');
        $this->graph->SetScale("textlin");
        $this->graph->SetShadow();
        $this->graph->title->Set($this->title);
        $this->graph->title->SetFont(FF_ARIAL,FS_NORMAL,9);
        $this->graph->xaxis->setTickLabels($arr1);
        if($type=="driver"){
            $this->type=1;
        }
        elseif($type=="customer"){
            $this->type=2;
        }
        elseif($type=="material"){
            $this->type=3;
        }
    }//construct

在浏览器上获取这个(前 2 个转储是我发送的,第二个是 class 正在转储的):

我认为你的构造函数中有一些初始化,特别是你的 $arr1 & $arr2 参数

   $this->.. = $arr1;
   $this->.. = $arr2 ;

应在您的 if(!is_array($arr1)||!is_array($arr2)){..

之前声明