Reputation: 129
So I have:
$first = "one";
$second = "two";
How can I get values of these variables in:
class TD
{
public $first;
public $second;
}
on the contrary, from here:
class TD
{
public $first = "one";
public $second = "two;
}
to here:
$... = ... ;
$... = ... ;
need to then use it in the query(for ex.):
SELECT * FROM table WHERE cell = $first
Upvotes: 0
Views: 32
Reputation:
you can also add a constructor and pass an array for multi params
class TD
{
public $find = [];
public function __construct($arr){
foreach($arr as $k=>$v){
$this->find[$k+1] = $v;
}
}
}
$array = ["one", "two", "tree"];
$td = new TD($array);
var_dump($td->find[1]);
var_dump($td->find[2]);
var_dump($td->find[3]);
Upvotes: 1
Reputation: 9396
Try the following:
$td = new TD;
$first = $td->first;
$second = $td->second;
The above variable $td
is an instance of the class TD
and it is accessing the classes properties, which are in this case $first
and $second
. Which is done like this $td->first
. Learn all about OOP in PHP.
Upvotes: 2