Error processing array array

I get the following error when running the following PHP code

class tableData
{
    private $row1 = array("Kalle1", "address1", "postal code1", "1@email.se", "070111001", "08111001");
    private $row2 = array("kalle2", "address2", "postcode2", "2@email.se", "070111002", "08111002");
    private $row3 = array("kalle3", "address3", "postcode3", "3@email.se", "070111003", "08111003");
    private $row4 = array("kalle4", "address4", "postcode4", "4@email.se", "070111004", "08111004");
    private $rader = array(array($row1),array($row2),array($row3),array($row4));
}

The error corresponds to the variable $rader:

Parse error: syntax error, unexpected '$ row1' (T_VARIABLE) waiting ')' in C: \ xampp \ htdocs \ test_k.php on line 15

Can someone help me fix this error?

+4
source share
2 answers

PHP User Guide :

This declaration of [class properties] may include initialization, but this initialization must be constant, that is, it must be evaluated at compile time and must not depend on the execution time of the information to be evaluated.

private $rader = array(array($row1),array($row2),array($row3),array($row4));

, $row1 , , , .

PHP , , $row1.

( ), setter, , , .

, , .

+2

, .

class tableData
{
    private $row1 = array("Kalle1", "address1", "postal code1", "1@email.se", "070111001", "08111001");
    private $row2 = array("kalle2", "address2", "postcode2", "2@email.se", "070111002", "08111002");
    private $row3 = array("kalle3", "address3", "postcode3", "3@email.se", "070111003", "08111003");
    private $row4 = array("kalle4", "address4", "postcode4", "4@email.se", "070111004", "08111004");
    private $rader;

    public function __construct() {
        $this->rader = array(
            array($this->row1),
            array($this->row2),
            array($this->row3),
            array($this->row4)
        );
    }

}

It is assumed that you intend to create a 3-level nested array.

+1
source

Source: https://habr.com/ru/post/1695948/


All Articles