I Have this array:
Array
(
[0] =>
bool own = 0
[1] =>
bool contr_name = 0
[2] =>
int all_votes = 0
[3] =>
bool contract_start = 0
[4] =>
bool contract_end = 0
[11] =>
clock T
[12] =>
int a
[13] =>
int candi_ID = 1
[14] =>
int voter_ID = 1
[15] =>
)
First of all I wanna save datatype, variable name and value. Second I wanna compare a variable like I have this variable in array or not and then find the value it's equal or not. Here is my code:
$variable = "own=1";
function searchTheValue($afterExp,$variable){
$datatype ="";
$variablename ="";
$equalto ="";
$varaiablevalue ="";
foreach ($afterExp as $newtest){
$afterExpBySpace = explode(" ",$newtest);
if (isset($afterExpBySpace[0])){
$datatype = !empty($afterExpBySpace[0]) ? $afterExpBySpace[0] : "";
}
if (isset($afterExpBySpace[1])){
$variablename = !empty($afterExpBySpace[1]) ? $afterExpBySpace[1] : "";
}
if (isset($afterExpBySpace[2])){
$equalto = !empty($afterExpBySpace[2]) ? $afterExpBySpace[2] : "";
}
if (isset($afterExpBySpace[2])){
if (!empty($afterExpBySpace[3])){
$varaiablevalue = $afterExpBySpace[3];
}else{
if($afterExpBySpace[3] == "0"){
$varaiablevalue = "0";
}
}
}
echo $datatype."datatype<br>" ;
echo $variablename."variable name<br>" ;
echo $equalto." = <br>";
echo $varaiablevalue." variable value";exit;
}
}
searchTheValue($afterExp,$variable);
So, here i have $variable="own=1";. I wanna search the variable in array that variable name is exist in array or not and the compare the value that it's equal to 1 or not. Any suggestion will be appreciable.
Just as cleaner version of what you have and also adding in the part which checks the variable you are looking for.
This code first processes the array of values, this means that these values can be used over and over (updated etc.) without have to convert them several times, then the
searchTheValue()function just looks for the value you pass in (comments in code for clarity)...Just to show the
$variablesdata (partially)...