cell formula
<?php | |
/** | |
* Cell formula plugin for Adminer. | |
* | |
* @link https://github.com/redfish-d86e/bd6e1bb86424bec46c1289a997cfe972/raw | |
* @author Tommy Tan, thf85@qq.com | |
*/ | |
class cellformula { | |
public function rowDescriptions( $rows, $foreignKeys){ | |
foreach ($rows as $key => $row) { | |
foreach ($row as $i => $val) { | |
if(strpos($val, '==') === 0){ | |
$rows[$key][$i] = eval('return '. self::processingFormula(substr($val, 2), $row) .';') ; | |
} | |
} | |
} | |
return $rows; | |
} | |
private static function processingFormula($str, $row) { | |
$start = strpos($str, '['); | |
if($start > 0 || $start === 0){ | |
$end = strpos($str, ']'); | |
$key = substr($str, $start+1, $end - $start - 1); | |
$str = str_ireplace('['.$key.']', $row[$key], $str); | |
$str = self::processingFormula($str, $row); | |
} | |
return $str; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment