Working with arrays in php

The problem is this:

can’t work with array values

there is an entry in the main file

   include('Node.inc');
    $obj = new Node();
    $obj->set();
    echo '< p>---------------Weight-------------< p>';
    $obj->get();

Node.inc file


class Node{
    private $mas = array();
function set(){
    global $mas;
    $mas[] = 1;
    //print_r($mas);
}
function get(){print_r($mas);}

}

When calling the set() function from the main file, the values ​​are naturally visible, but not in the get() function. How to make it visible without inserting return?


Answer 1, authority 100%

class Node{
  private $mas = array();
  function set(){
      $this->mas[] = 1;
      //print_r($mas);
  }
  function get(){
    print_r($this->mas);
  }
}

I think you should do something like this


Answer 2, authority 100%

You have a field in your class declared:

private $mas = array();

But for some reason you don’t use it:

function set() {
    $this->mas[] = 1;
    print_r($this->mas);
}
function get(){
    print_r($this->mas);
}