Skip to content

Instantly share code, notes, and snippets.

@devpruthvi
Created February 1, 2015 15:10
Show Gist options
  • Select an option

  • Save devpruthvi/ec3fcfeefc5de537b93e to your computer and use it in GitHub Desktop.

Select an option

Save devpruthvi/ec3fcfeefc5de537b93e to your computer and use it in GitHub Desktop.
Project Help for varma bro
<?php
//$a is the Array with final result that we gathered after traversing through all the words in the question
$a = array(
"Synthesize" => 3,
"Evaluate" => 3,
"Applying" => 3
);
//$priorities is just a array with constants that shouldn't be replaced which are ordered a/c to booles's taxonomy thing
$priorities = array(
"Synthesize" => 6,
"Evaluate" => 5,
"Analyzing" => 4,
"Applying" => 3,
"Understanding" => 2,
"Remembering" => 1,
);
//$maximumValues has the maximum value from $a, here it is "3"
$maximumValue = max($a);
//$maxKeys has all the keys that have value $maximumValue i.e., 3 here, which gives ("Synthesize","Evaluate","Applying")
//because all the keys have the $maximumValue of 3
$maxKeys = array_keys($a,$maximumValue);
//the condition is checking if more than one key has same maximumValue, in this case all have the maximumValue
//by using the length of the array that we got before ($maxKeys);
if(sizeof($maxKeys) > 1)
{
//if length of array is > 1, it means more keys have same value, we determine the best one using booles taxonomy and out $priorities array
$maxpri = 0;
//intiate maxpri with least priority that is not in priorities array i.e., 0
foreach($maxKeys as $currkey => $value)
{
//if any key in array has greater than our current maxpri value, replace maxpri with that value, do this for all the array
if($priorities[$value] > $maxpri)
$maxpri = $priorities[$value];
}
//finally we have the value of maximum priority key in $maxpri
//just print the key with that value in $priorities and that will be our result
echo array_search($maxpri,$priorities)."\r\n";
}
else
{
//else just print the one and only one element in the maxKeys that has maximum Value!
echo $maxKeys[0]."\r\n";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment