我有这个变量$variable = "own=1,contract_start=1";,我想找到这个变量一个数组。数组名称是 $variables 这是我的数组:
Array
(
[own] => Array
(
[type] => bool
[value] => 0
)
[contr_name] => Array
(
[type] => bool
[value] => 0
)
[all_votes] => Array
(
[type] => int
[value] => 0
)
[contract_start] => Array
(
[type] => bool
[value] => 0
)
[contract_end] => Array
(
[type] => bool
[value] => 0
)
[T] => Array
(
[type] => clock
[value] =>
)
[a] => Array
(
[type] => int
[value] => 1
)
[candi_ID] => Array
(
[type] => int
[value] => 1
)
[voter_ID] => Array
(
[type] => int
[value] => 1
)
[] => Array
(
[type] =>
[value] =>
)
)
如果该值不等于现有值一个数组,所以我想用变量值更新该值。这是我的代码:
$variable = "own=1,contract_start=1";
function updateTheValue($variables,$variable) {
// Split variable looking for into name and value
$vars = explode(",", $variable);
$match = false;
foreach ($vars as $var){
$expbyequal = explode("=", $var);
// If this variable is set
if ( isset($variables [trim($expbyequal[0])]) ) {
// Compare value with stored value
if ( $variables [trim($expbyequal[0])]['value'] == trim($expbyequal[1]) ) {
$match = true;
}else{
$variables[trim($expbyequal[0])] = ["value" => trim($expbyequal[1])]);
$match = false;
}
}
}
return $match;
}
$testing = updateTheValue($variables,$variable);
任何想法都将是可观的。
临摹微笑
LEATH
MYYA