<?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);
- Output for 7.1.26 - 7.1.33, 7.2.17 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
- Array
(
[own] => Array
(
[type] => bool
[value] => 1
)
[contr_name] => Array
(
[type] => bool
[value] => 0
)
[all_votes] => Array
(
[type] => int
[value] => 0
)
[contract_start] => Array
(
[type] => bool
[value] => 1
)
[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
)
)
preferences:
131.94 ms | 410 KiB | 5 Q