I have a two dimensional array that reads values from another array in order to decide on how itself should be altered. That’s 3 loops. The decision-taking is in part handled by a method which further sends relevant arguments to their respective methods in another class.
One of these methods returns a value that relies on precomputed evaluation of the parent object. A JavaScript analogy would be akin to using event delegation to obtain a live list of nodes. This method requires the updated array which unfortunately happens to be locked during the loop transaction.
How may I access the new list without adding an extra loop to the friar? I might add, without hard coding the method in our decision making method. Something like
if ($needLiveList) $nextClass->specificMethod($args)
I could create a new array after traversing array level 1 but my constraints are
- it’s pointless if I have to descend another loop just because
- My hands are somewhat tied in terms of parameters I can pass to the processing method. Every function in that class is fashioned with the same signature so I can pass in arguments from a central agent.
The implementation below may be hard to follow, that’s why I explained first
class1
public function formInterface (&$processed, $tools) {
$cache = [];
foreach ($tools as $selection => $eq) {
foreach ($processed as $tea => &$lump) {
foreach ($lump as $key => &$frequency) {
preg_match('/(?<![a-z-])(' . $selection . ')([ -].+)?$/i', $key, $match);
$match = array_filter($match);
if (!empty($match) && !stripos($key, 'orrect')) { // correct score might hold 1
if (!isset($match[2]) && $frequency < 7) unset($lump[$key]);
else {
if (isset($cache[$match[1]])) $newFreq = $cache[$match[1]];
else $newFreq = $this->confirmValidity($tools[$match[1]], $tea);
if (!$newFreq) unset($lump[$key]);
else {
$frequency = 10;
$cache[$match[1]] = 10;
}
}
}
}
// $lump = $this->omitRedundant($lump);
}
}
return $processed;
}
/**
* documentation: checks to see if head to head likelihood tallies with current form
*
* @param {condition}:String. calculation
* @param {parent}:String. the name of the teams which these predictions are under
*
* @return bool
**/
private function confirmValidity ($condition, $parent) {
$args = explode('\\', $condition);
$equation = $args[0];
$methodArg = end($args);
$directives = ['getRes', 'hashmapArg', 'reflect'];
$ppg = explode('-', $parent)[0];
$culprit = array_filter($this->origDataSet, function ($fixture) use ($ppg) {
return $fixture['PPG'] == $ppg;
});
$method = $directives[count($args)-1];
$opts = ['caller' => $this->getHalves()[$parent], 'methodArg' => $methodArg];
$form = new CurrentForm (array_values($culprit)[0]);
return $form->$method($equation, $opts); // these methods should probabaly be called from the instance's constructor
}
class2
// this needs to run after fresh properties have been evaluated. the context object is sealed during the loop
public function reflect ($eq, $opts) {
$parent = $opts['caller']; // this is a stale object
$eq = preg_replace_callback('/\'(.+?)\'/', function ($match) use ($parent) {
return $parent[$match[1]];
}, $eq);
return $this->getRes($eq, $opts);
}
also
$tools = [
'key1' => (17 >= 15),
2 => key1 && (14 - 10 == 4)\true // meaning read from the current object
];