I'm playing with php code to move from procedural to objects: I created a class called data, in a file called
data2.php and used this in useData.php where I used some procedural and some use of data class.
data class as follows:
<?
class data
{
var $anArray;
var $element;
public function load_Array($data)
{
$this->anArray = array();
array_push($this->anArray,$data);
// data from loading object is $andy->load_Array("andy","bill");
//only the first entry "andy" is getting loaded
$this->element =$this->anArray[0];
}
function get_element()
{
echo "the output using function is: ". $this->element;
}
}
?>
then used this class in useData.php as follows:
<?php
include("data2.php");
$still = array("andy","bill","sid");
echo "the elements in array using procedural is: ".$still[0]." and ".$still[1]."<br>";
$andy = new data();
$andy->load_Array("andy","bill");
$andy->get_element();
?>
The output using useData.php in browser being :
the elements in array using procedural is: andy and bill
the output using function is: andy
On this line :
public function load_Array($data)
it seems that only "andy" is getting loaded into array, since if I put a "1" instead of "0" in this line
$this->element =$this->anArray[0];
i get an error I guess because there is no second element in the array.
why isn't the second element of "bill" getting loaded into array using this line :
$andy->load_Array("andy","bill");