Php 如何将值设置为类似更改方法的数组?

Php 如何将值设置为类似更改方法的数组?,php,arrays,set,arrows,Php,Arrays,Set,Arrows,我想用钥匙设定一个数组的值 我只是想知道拉威尔是怎么做到的 这是laravel代码的雄辩更新查询 $variable=Model::find(3); $variable->columnname="name"; $variable->save(); 这是我的密码 $variable=["name"=>"Eric","email"=>"example@gmail.com"]; $variable->name="jack"; $variable->email="

我想用钥匙设定一个数组的值

我只是想知道拉威尔是怎么做到的

这是laravel代码的雄辩更新查询

$variable=Model::find(3);
$variable->columnname="name";
$variable->save();
这是我的密码

$variable=["name"=>"Eric","email"=>"example@gmail.com"]; 
$variable->name="jack";
$variable->email="testest@gmail.com";
print_r($variable); or $query="update tblname ..."
它不工作,它给我错误


这个系统是如何工作的

我想你把一些东西混在一起了

// Array syntax
$array = [];
$array['key'] = 'value'; // adding "value" to the array with the key "key"
$array['key'] = 'newValue'; // Values can be changed like this.

// Object syntax
$obj = new stdClass;
$obj->key = 'value'; // adding "value to the object with as the attribute "key"
但这只适用于标准类。当您使用已经存在的类(在您的示例“模型”中)时,您不能总是访问或更改属性。这就是为什么你经常可以看到这样的方法

$obj->getName(); //to get the value of "name" of the class
$obj->setName(); // to set...
我做了一个快速搜索。我认为链接应该澄清一些事情。对于您的代码:

// option 1, create a class with getter and setter, see link
// option 2
$variable = new stdClass;
$variable->name = "Jack";
...

真的不知道你在问什么。没有链接,两个代码段没有任何关联。
->
用于对象,而不是数组。你需要定义一个类。我只是想知道这个laravel系统是如何工作的,find方法通过id返回一个数组,我可以使用variable->keyarrayiscolumnname=setvalue。laravel是如何通过这种方式获得值的?你能给我一些示例代码吗?