如何在使用pthreads时更新php类数组值
正如您所看到的代码,我正在通过函数addValue更新数组的值,如果在dataFields数组中设置了键,那么它将得到更新,但在这种情况下,当我尝试调用函数时,它不会发生: 增值(“财产”、“id”、“1”);通过函数setVariables() (见下面的输出) 它打印$data的值,并打印“是”。 未更新类变量数据字段 [编辑] 当我使用线程扩展类时,它不会得到更新,但当我不使用线程扩展类时,它会得到更新如何在使用pthreads时更新php类数组值,php,class,Php,Class,正如您所看到的代码,我正在通过函数addValue更新数组的值,如果在dataFields数组中设置了键,那么它将得到更新,但在这种情况下,当我尝试调用函数时,它不会发生: 增值(“财产”、“id”、“1”);通过函数setVariables() (见下面的输出) 它打印$data的值,并打印“是”。 未更新类变量数据字段 [编辑] 当我使用线程扩展类时,它不会得到更新,但当我不使用线程扩展类时,它会得到更新 class Field extends Thread{ public
class Field extends Thread{
public $dataFields;
public function addValue($table,$key,$data){
print_r($this->dataFields[$table]);
echo "\ndata: ".$data."\n";
if(isset($this->dataFields[$table][$key])){
$this->dataFields[$table][$key]= $data;
echo "yes\n";
}
else echo "no\n";
print_r($this->dataFields[$table]);
}
public function setVariables($con){
$result = mysqli_query($con,"select * from property,city limit 1");
$row=mysqli_fetch_fields($result);
foreach ($row as $key => $value) {
$propData[$value->table][$value->name]="";
}
$propData["property"]["portalId"]=2;
$propData["property"]["area"]="delhi";
$this->dataFields=$propData;
$this->addValue("property","id","1");
//print_r($this->dataFields);
$this->dataFields["property"]["id"]=1;
var_dump($propData);
var_dump($this->dataFields);
}
}
我可以在5.6.3中为我确认以下工作:
Array
(
[id] =>
[portalId] => 2
[area] => delhi
)
data: 1
yes
Array
(
[id] =>
[portalId] => 2
[area] => delhi
)
array(2) {
["city"]=>
array(3) {
["id"]=>
string(0) ""
["name"]=>
string(0) ""
["otherNames"]=>
string(0) ""
}
["property"]=>
array(3) {
["id"]=>
string(0) ""
["portalId"]=>
int(2)
["area"]=>
string(5) "delhi"
}
}
array(2) {
["city"]=>
array(3) {
["id"]=>
string(0) ""
["name"]=>
string(0) ""
["otherNames"]=>
string(0) ""
}
["property"]=>
array(3) {
["id"]=>
string(0) ""
["portalId"]=>
int(2)
["area"]=>
string(5) "delhi"
}
}
输出:
class Field {
public $dataFields;
public function addValue($table,$key,$data){
print_r($this->dataFields[$table]);
echo "\ndata: ".$data."\n";
if(isset($this->dataFields[$table][$key])){
$this->dataFields[$table][$key]= $data;
echo "yes\n";
}
else echo "no\n";
print_r($this->dataFields[$table]);
}
public function setVariables(){
$propData["property"]["id"] = '';
$propData["property"]["portalId"]=2;
$propData["property"]["area"]="delhi";
$this->dataFields=$propData;
$this->addValue("property","id","1");
//print_r($this->dataFields);
}
}
$field = new Field;
$field->setVariables();
我建议重新安装最新版本的PHP。请向我们展示您的输入、准确输出和预期输出。(对我来说很好)还显示您的完整代码为什么输出:
data:DEFAULT
而不是data:1
?请给我们看完整的代码对不起,我复制了不同测试用例的输出,我现在已经更正了!更改addValue(“属性”、“id”、“1”)代码>->$this->addValue(“属性”、“id”、“1”)代码>这对你有用吗?将你的print\u r()
调用更改为var\u dump()
,如果有任何“隐藏”字符,请查看源代码。这对OP或任何人都没有帮助,这不是答案。你可以在OP的问题下发表评论。每个人都会说:这对我有用,我们这里有200个答案@ayushlodhi您在问题上发布的输出是从脚本的源代码复制的吗?@ayushlodhi您是否单击:右键单击页面->查看源代码
,并从那里复制了var_转储?我复制了表单terminal@Rizier123你在《华尔街日报》的第13条评论中发布了与我完全相同的东西问题lol
Array
(
[id] =>
[portalId] => 2
[area] => delhi
)
data: 1
yes
Array
(
[id] => 1
[portalId] => 2
[area] => delhi
)