Простой вопрос, как преобразовать ассоциативный массив в переменные в классе? Я знаю, что есть кастинг, чтобы сделать (object) $myarray
или что-то еще, но это создаст новый stdClass и не поможет мне. Есть ли какие-либо простые одно- или двухлинейные методы, чтобы каждая пара $key => $value
в моем массиве была переменной $key = $value
для моего класса? Я не считаю логичным использовать цикл foreach для этого, мне было бы лучше просто преобразовать его в stdClass и сохранить его в переменной, не так ли?
class MyClass {
var $myvar; // I want variables like this, so they can be references as $this->myvar
function __construct($myarray) {
// a function to put my array into variables
}
}