<?php
$variables =
[ "own" => [ "type" => "bool", "value" => 0 ],
"contr_name" =>
[
"type" => "bool",
"value" => 0
],
"all_votes" =>
[
"type" => "int",
"value" => 0
],
"contract_start" =>
[
"type" => "bool",
"value" => 0
],
"contract_end" =>
[
"type" => "bool",
"value" => 0
],
"T" =>
[
"type" => "clock",
"value" => ''
],
"a" =>
[
"type" => "int",
"value" => 1
],
"candi_ID" =>
[
"type" => "int",
"value" => 1
],
"voter_ID" =>
[
"type" => "int",
"value" => 1
],
/*
[] =>
[
"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 key exists in main keys
if ( in_array(trim($expbyequal[0]), array_keys($variables)) ) {
// 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;
}
updateTheValue($variables,$variable);
print_r($variables);
preferences:
23.56 ms | 408 KiB | 5 Q