本文整理汇总了PHP中PHPExcel_Calculation_Functions::flattenArray方法的典型用法代码示例。如果您正苦于以下问题:PHP PHPExcel_Calculation_Functions::flattenArray方法的具体用法?PHP PHPExcel_Calculation_Functions::flattenArray怎么用?PHP PHPExcel_Calculation_Functions::flattenArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHPExcel_Calculation_Functions
的用法示例。
在下文中一共展示了PHPExcel_Calculation_Functions::flattenArray方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: MATCH
/**
* MATCH
*
* The MATCH function searches for a specified item in a range of cells
*
* @param lookup_value The value that you want to match in lookup_array
* @param lookup_array The range of cells being searched
* @param match_type The number -1, 0, or 1. -1 means above, 0 means exact match, 1 means below. If match_type is 1 or -1, the list has to be ordered.
* @return integer The relative position of the found item
*/
public static function MATCH($lookup_value, $lookup_array, $match_type = 1)
{
$lookup_array = PHPExcel_Calculation_Functions::flattenArray($lookup_array);
$lookup_value = PHPExcel_Calculation_Functions::flattenSingleValue($lookup_value);
$match_type = is_null($match_type) ? 1 : (int) PHPExcel_Calculation_Functions::flattenSingleValue($match_type);
// MATCH is not case sensitive
$lookup_value = strtolower($lookup_value);
// lookup_value type has to be number, text, or logical values
if (!is_numeric($lookup_value) && !is_string($lookup_value) && !is_bool($lookup_value)) {
return PHPExcel_Calculation_Functions::NA();
}
// match_type is 0, 1 or -1
if ($match_type !== 0 && $match_type !== -1 && $match_type !== 1) {
return PHPExcel_Calculation_Functions::NA();
}
// lookup_array should not be empty
$lookupArraySize = count($lookup_array);
if ($lookupArraySize <= 0) {
return PHPExcel_Calculation_Functions::NA();
}
// lookup_array should contain only number, text, or logical values, or empty (null) cells
foreach ($lookup_array as $i => $lookupArrayValue) {
// check the type of the value
if (!is_numeric($lookupArrayValue) && !is_string($lookupArrayValue) && !is_bool($lookupArrayValue) && !is_null($lookupArrayValue)) {
return PHPExcel_Calculation_Functions::NA();
}
// convert strings to lowercase for case-insensitive testing
if (is_string($lookupArrayValue)) {
$lookup_array[$i] = strtolower($lookupArrayValue);
}
if (is_null($lookupArrayValue) && ($match_type == 1 || $match_type == -1)) {
$lookup_array = array_slice($lookup_array, 0, $i - 1);
}
}
// if match_type is 1 or -1, the list has to be ordered
if ($match_type == 1) {
asort($lookup_array);
$keySet = array_keys($lookup_array);
} elseif ($match_type == -1) {
arsort($lookup_array);
$keySet = array_keys($lookup_array);
}
// **
// find the match
// **
// loop on the cells
// var_dump($lookup_array);
// echo '<br>';
foreach ($lookup_array as $i => $lookupArrayValue) {
if ($match_type == 0 && $lookupArrayValue == $lookup_value) {
// exact match
return ++$i;
} elseif ($match_type == -1 && $lookupArrayValue <= $lookup_value) {
// echo '$i = '.$i.' => ';
// var_dump($lookupArrayValue);
// echo '<br>';
// echo 'Keyset = ';
// var_dump($keySet);
// echo '<br>';
$i = array_search($i, $keySet);
// echo '$i='.$i.'<br>';
// if match_type is -1 <=> find the smallest value that is greater than or equal to lookup_value
if ($i < 1) {
// 1st cell was allready smaller than the lookup_value
break;
} else {
// the previous cell was the match
return $keySet[$i - 1] + 1;
}
} elseif ($match_type == 1 && $lookupArrayValue >= $lookup_value) {
// echo '$i = '.$i.' => ';
// var_dump($lookupArrayValue);
// echo '<br>';
// echo 'Keyset = ';
// var_dump($keySet);
// echo '<br>';
$i = array_search($i, $keySet);
// echo '$i='.$i.'<br>';
// if match_type is 1 <=> find the largest value that is less than or equal to lookup_value
if ($i < 1) {
// 1st cell was allready bigger than the lookup_value
break;
} else {
// the previous cell was the match
return $keySet[$i - 1] + 1;
}
}
}
// unsuccessful in finding a match, return #N/A error value
return PHPExcel_Calculation_Functions::NA();
//.........这里部分代码省略.........
示例2: WORKDAY
/**
* WORKDAY
*
* @param mixed Start date
* @param mixed number of days for adjustment
* @param array of mixed Optional Date Series
* @return long Interval between the dates
*/
public static function WORKDAY($startDate, $endDays)
{
// Retrieve the mandatory start date and days that are referenced in the function definition
$startDate = PHPExcel_Calculation_Functions::flattenSingleValue($startDate);
$endDays = (int) PHPExcel_Calculation_Functions::flattenSingleValue($endDays);
// Flush the mandatory start date and days that are referenced in the function definition, and get the optional days
$dateArgs = PHPExcel_Calculation_Functions::flattenArray(func_get_args());
array_shift($dateArgs);
array_shift($dateArgs);
if (is_string($startDate = self::_getDateValue($startDate)) || !is_numeric($endDays)) {
return PHPExcel_Calculation_Functions::VALUE();
}
$startDate = (double) floor($startDate);
// If endDays is 0, we always return startDate
if ($endDays == 0) {
return $startDate;
}
$decrementing = $endDays < 0 ? True : False;
// Adjust the start date if it falls over a weekend
$startDoW = self::DAYOFWEEK($startDate, 3);
if (self::DAYOFWEEK($startDate, 3) >= 5) {
$startDate += $decrementing ? -$startDoW + 4 : 7 - $startDoW;
$decrementing ? $endDays++ : $endDays--;
}
// Add endDays
$endDate = (double) $startDate + intval($endDays / 5) * 7 + $endDays % 5;
// Adjust the calculated end date if it falls over a weekend
$endDoW = self::DAYOFWEEK($endDate, 3);
if ($endDoW >= 5) {
$endDate += $decrementing ? -$endDoW + 4 : 7 - $endDoW;
}
// Test any extra holiday parameters
if (count($dateArgs) > 0) {
$holidayCountedArray = $holidayDates = array();
foreach ($dateArgs as $holidayDate) {
if (!is_null($holidayDate) && trim($holidayDate) > '') {
if (is_string($holidayDate = self::_getDateValue($holidayDate))) {
return PHPExcel_Calculation_Functions::VALUE();
}
if (self::DAYOFWEEK($holidayDate, 3) < 5) {
$holidayDates[] = $holidayDate;
}
}
}
if ($decrementing) {
rsort($holidayDates, SORT_NUMERIC);
} else {
sort($holidayDates, SORT_NUMERIC);
}
foreach ($holidayDates as $holidayDate) {
if ($decrementing) {
if ($holidayDate <= $startDate && $holidayDate >= $endDate) {
if (!in_array($holidayDate, $holidayCountedArray)) {
--$endDate;
$holidayCountedArray[] = $holidayDate;
}
}
} else {
if ($holidayDate >= $startDate && $holidayDate <= $endDate) {
if (!in_array($holidayDate, $holidayCountedArray)) {
++$endDate;
$holidayCountedArray[] = $holidayDate;
}
}
}
// Adjust the calculated end date if it falls over a weekend
$endDoW = self::DAYOFWEEK($endDate, 3);
if ($endDoW >= 5) {
$endDate += $decrementing ? -$endDoW + 4 : 7 - $endDoW;
}
}
}
switch (PHPExcel_Calculation_Functions::getReturnDateType()) {
case PHPExcel_Calculation_Functions::RETURNDATE_EXCEL:
return (double) $endDate;
break;
case PHPExcel_Calculation_Functions::RETURNDATE_PHP_NUMERIC:
return (int) PHPExcel_Shared_Date::ExcelToPHP($endDate);
break;
case PHPExcel_Calculation_Functions::RETURNDATE_PHP_OBJECT:
return PHPExcel_Shared_Date::ExcelToPHPObject($endDate);
break;
}
}
示例3: _calculateTopTenValue
private function _calculateTopTenValue($columnID, $startRow, $endRow, $ruleType, $ruleValue)
{
$range = $columnID . $startRow . ':' . $columnID . $endRow;
$dataValues = PHPExcel_Calculation_Functions::flattenArray($this->_workSheet->rangeToArray($range, NULL, TRUE, FALSE));
$dataValues = array_filter($dataValues);
if ($ruleType == PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_COLUMN_RULE_TOPTEN_TOP) {
rsort($dataValues);
} else {
sort($dataValues);
}
return array_pop(array_slice($dataValues, 0, $ruleValue));
}
示例4: CONCATENATE
/**
* CONCATENATE
*
* @return string
*/
public static function CONCATENATE()
{
// Return value
$returnValue = '';
// Loop through arguments
$aArgs = PHPExcel_Calculation_Functions::flattenArray(func_get_args());
foreach ($aArgs as $arg) {
if (is_bool($arg)) {
if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) {
$arg = (int) $arg;
} else {
$arg = $arg ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE();
}
}
$returnValue .= $arg;
}
// Return
return $returnValue;
}
示例5: _showTypeDetails
/**
* Format type and details of an operand for display in the log (based on operand type)
*
* @param mixed $value First matrix operand
* @return mixed
*/
private static function _showTypeDetails($value)
{
$testArray = PHPExcel_Calculation_Functions::flattenArray($value);
if (count($testArray) == 1) {
$value = array_pop($testArray);
}
switch (gettype($value)) {
case 'double':
case 'float':
$typeString = 'a floating point number';
break;
case 'integer':
$typeString = 'an integer number';
break;
case 'boolean':
$typeString = 'a boolean';
break;
case 'array':
$typeString = 'a matrix';
break;
case 'string':
if ($value == '') {
return 'an empty string';
} elseif ($value[0] == '#') {
return 'a ' . $value . ' error';
} else {
$typeString = 'a string';
}
break;
case 'NULL':
return 'a null value';
}
return $typeString . ' with a value of ' . self::_showValue($value);
}
示例6: _showTypeDetails
/**
* Format type and details of an operand for display in the log (based on operand type)
*
* @param mixed $value First matrix operand
* @return mixed
*/
private static function _showTypeDetails($value)
{
$testArray = PHPExcel_Calculation_Functions::flattenArray($value);
if (count($testArray) == 1) {
$value = array_pop($testArray);
}
if (is_null($value)) {
return 'a null value';
} elseif (is_float($value)) {
$typeString = 'a floating point number';
} elseif (is_int($value)) {
$typeString = 'an integer number';
} elseif (is_bool($value)) {
$typeString = 'a boolean';
} elseif (is_array($value)) {
$typeString = 'a matrix';
} else {
if ($value == '') {
return 'an empty string';
} elseif ($value[0] == '#') {
return 'a ' . $value . ' error';
} else {
$typeString = 'a string';
}
}
return $typeString . ' with a value of ' . self::_showValue($value);
}
示例7: calculate
/**
* Calculate cell value (using formula)
*
* @param PHPExcel_Cell $pCell Cell to calculate
* @return mixed
* @throws Exception
*/
public function calculate(PHPExcel_Cell $pCell = null)
{
// Return value
$returnValue = '';
// Is the value present in calculation cache?
if ($this->getCalculationCacheEnabled()) {
if (isset($this->_calculationCache[$pCell->getParent()->getTitle()][$pCell->getCoordinate()])) {
if (time() + microtime() - $this->_calculationCache[$pCell->getParent()->getTitle()][$pCell->getCoordinate()]['time'] < $this->_calculationCacheExpirationTime) {
// Return result
$returnValue = $this->_calculationCache[$pCell->getParent()->getTitle()][$pCell->getCoordinate()]['data'];
if (is_array($returnValue) && self::$returnArrayAsType == self::RETURN_ARRAY_AS_VALUE) {
return array_shift(PHPExcel_Calculation_Functions::flattenArray($returnValue));
}
return $returnValue;
} else {
unset($this->_calculationCache[$pCell->getParent()->getTitle()][$pCell->getCoordinate()]);
}
}
}
// Formula
$formula = $pCell->getValue();
// Executable formula array
$executableFormulaArray = array();
// Parse formula into a tree of tokens
$objParser = new PHPExcel_Calculation_FormulaParser($formula);
// Loop trough parsed tokens and create an executable formula
$inFunction = false;
$token = null;
$tokenCount = $objParser->getTokenCount();
for ($i = 0; $i < $tokenCount; ++$i) {
$token = $objParser->getToken($i);
$tokenType = $token->getTokenType();
$tokenSubType = $token->getTokenSubType();
$tokenValue = $token->getValue();
// Is it a cell reference?
if ($tokenType == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND && $tokenSubType == PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_RANGE) {
// Adjust reference
$reference = str_replace('$', '', $tokenValue);
// Add to executable formula array
$executableFormulaArray[] = '$this->extractRange("' . $reference . '", $pCell->getParent())';
continue;
}
// Is it a concatenation operator?
if ($tokenType == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERATORINFIX && $tokenSubType == PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_CONCATENATION) {
// Add to executable formula array
$executableFormulaArray[] = '.';
continue;
}
// Is it a logical operator?
if ($tokenType == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERATORINFIX && $tokenSubType == PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_LOGICAL) {
// Temporary variable
$tmp = '';
switch ($tokenValue) {
case '=':
$tmp = '==';
break;
case '<>':
$tmp = '!=';
break;
default:
$tmp = $tokenValue;
}
// Add to executable formula array
$executableFormulaArray[] = $tmp;
continue;
}
// Is it a subexpression?
if ($tokenType == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_SUBEXPRESSION) {
// Temporary variable
$tmp = '';
switch ($tokenSubType) {
case PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_START:
$tmp = '(';
break;
case PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_STOP:
$tmp = ')';
break;
}
// Add to executable formula array
$executableFormulaArray[] = $tmp;
continue;
}
// Is it a function?
if ($tokenType == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_FUNCTION) {
// Temporary variable
$tmp = '';
// Check the function type
if ($tokenValue == 'ARRAY' || $tokenValue == 'ARRAYROW') {
// An array or an array row...
$tmp = 'array(';
} else {
// A regular function call...
switch ($tokenSubType) {
//.........这里部分代码省略.........
示例8: VARP
/**
* VARP
*
* Calculates variance based on the entire population
*
* Excel Function:
* VARP(value1[,value2[, ...]])
*
* @access public
* @category Statistical Functions
* @param mixed $arg,... Data values
* @return float
*/
public static function VARP()
{
// Return value
$returnValue = PHPExcel_Calculation_Functions::DIV0();
$summerA = $summerB = 0;
// Loop through arguments
$aArgs = PHPExcel_Calculation_Functions::flattenArray(func_get_args());
$aCount = 0;
foreach ($aArgs as $arg) {
if (is_bool($arg)) {
$arg = (int) $arg;
}
// Is it a numeric value?
if (is_numeric($arg) && !is_string($arg)) {
$summerA += $arg * $arg;
$summerB += $arg;
++$aCount;
}
}
// Return
if ($aCount > 0) {
$summerA *= $aCount;
$summerB *= $summerB;
$returnValue = ($summerA - $summerB) / ($aCount * $aCount);
}
return $returnValue;
}
示例9: refresh
public function refresh(PHPExcel_Worksheet $worksheet, $flatten = TRUE)
{
if ($this->_dataSource !== NULL) {
$calcEngine = PHPExcel_Calculation::getInstance();
$newDataValues = PHPExcel_Calculation::_unwrapResult($calcEngine->_calculateFormulaValue('=' . $this->_dataSource, NULL, $worksheet->getCell('A1')));
if ($flatten) {
$this->_dataValues = PHPExcel_Calculation_Functions::flattenArray($newDataValues);
} else {
$newArray = array_values(array_shift($newDataValues));
foreach ($newArray as $i => $newDataSet) {
$newArray[$i] = array($newDataSet);
}
foreach ($newDataValues as $newDataSet) {
$i = 0;
foreach ($newDataSet as $newDataVal) {
array_unshift($newArray[$i++], $newDataVal);
}
}
$this->_dataValues = $newArray;
}
$this->_pointCount = count($this->_dataValues);
}
}
示例10: IMPRODUCT
/**
* IMPRODUCT
*
* Returns the product of two or more complex numbers in x + yi or x + yj text format.
*
* Excel Function:
* IMPRODUCT(complexNumber[,complexNumber[,...]])
*
* @param string $complexNumber,... Series of complex numbers to multiply
* @return string
*/
public static function IMPRODUCT()
{
// Return value
$returnValue = self::_parseComplex('1');
$activeSuffix = '';
// Loop through the arguments
$aArgs = PHPExcel_Calculation_Functions::flattenArray(func_get_args());
foreach ($aArgs as $arg) {
$parsedComplex = self::_parseComplex($arg);
$workValue = $returnValue;
if ($parsedComplex['suffix'] != '' && $activeSuffix == '') {
$activeSuffix = $parsedComplex['suffix'];
} elseif ($parsedComplex['suffix'] != '' && $activeSuffix != $parsedComplex['suffix']) {
return PHPExcel_Calculation_Functions::NaN();
}
$returnValue['real'] = $workValue['real'] * $parsedComplex['real'] - $workValue['imaginary'] * $parsedComplex['imaginary'];
$returnValue['imaginary'] = $workValue['real'] * $parsedComplex['imaginary'] + $workValue['imaginary'] * $parsedComplex['real'];
}
if ($returnValue['imaginary'] == 0.0) {
$activeSuffix = '';
}
return self::COMPLEX($returnValue['real'], $returnValue['imaginary'], $activeSuffix);
}
示例11: refresh
public function refresh(PHPExcel_Worksheet $worksheet, $flatten = TRUE)
{
if ($this->_dataSource !== NULL) {
$calcEngine = PHPExcel_Calculation::getInstance($worksheet->getParent());
$newDataValues = PHPExcel_Calculation::_unwrapResult($calcEngine->_calculateFormulaValue('=' . $this->_dataSource, NULL, $worksheet->getCell('A1')));
if ($flatten) {
$this->_dataValues = PHPExcel_Calculation_Functions::flattenArray($newDataValues);
foreach ($this->_dataValues as &$dataValue) {
if (!empty($dataValue) && $dataValue[0] == '#') {
$dataValue = 0.0;
}
}
unset($dataValue);
} else {
$cellRange = explode('!', $this->_dataSource);
if (count($cellRange) > 1) {
list(, $cellRange) = $cellRange;
}
$dimensions = PHPExcel_Cell::rangeDimension(str_replace('$', '', $cellRange));
if ($dimensions[0] == 1 || $dimensions[1] == 1) {
$this->_dataValues = PHPExcel_Calculation_Functions::flattenArray($newDataValues);
} else {
$newArray = array_values(array_shift($newDataValues));
foreach ($newArray as $i => $newDataSet) {
$newArray[$i] = array($newDataSet);
}
foreach ($newDataValues as $newDataSet) {
$i = 0;
foreach ($newDataSet as $newDataVal) {
array_unshift($newArray[$i++], $newDataVal);
}
}
$this->_dataValues = $newArray;
}
}
$this->_pointCount = count($this->_dataValues);
}
}
示例12: refresh
public function refresh(PHPExcel_Worksheet $worksheet)
{
if ($this->_dataSource !== NULL) {
$calcEngine = PHPExcel_Calculation::getInstance();
$newDataValues = PHPExcel_Calculation::_unwrapResult($calcEngine->_calculateFormulaValue('=' . $this->_dataSource, NULL, $worksheet->getCell('A1')));
$this->_dataValues = PHPExcel_Calculation_Functions::flattenArray($newDataValues);
}
}
示例13: setDataValues
/**
* Set Series Data Values
*
* @param array $dataValues
* @param boolean $refreshDataSource
* TRUE - refresh the value of _dataSource based on the values of $dataValues
* FALSE - don't change the value of _dataSource
* @return PHPExcel_Chart_DataSeriesValues
*/
public function setDataValues($dataValues = array(), $refreshDataSource = true)
{
$this->_dataValues = PHPExcel_Calculation_Functions::flattenArray($dataValues);
$this->_pointCount = count($dataValues);
if ($refreshDataSource) {
// TO DO
}
return $this;
}
示例14: _processTokenStack
//.........这里部分代码省略.........
$arg = $stack->pop();
$a = $argCount - $i - 1;
if ($passByReference && isset(self::$_PHPExcelFunctions[$functionName]['passByReference'][$a]) && self::$_PHPExcelFunctions[$functionName]['passByReference'][$a]) {
if ($arg['reference'] === NULL) {
$args[] = $cellID;
if ($functionName != 'MKMATRIX') {
$argArrayVals[] = $this->_showValue($cellID);
}
} else {
$args[] = $arg['reference'];
if ($functionName != 'MKMATRIX') {
$argArrayVals[] = $this->_showValue($arg['reference']);
}
}
} else {
$args[] = self::_unwrapResult($arg['value']);
if ($functionName != 'MKMATRIX') {
$argArrayVals[] = $this->_showValue($arg['value']);
}
}
}
// Reverse the order of the arguments
krsort($args);
if ($passByReference && $argCount == 0) {
$args[] = $cellID;
$argArrayVals[] = $this->_showValue($cellID);
}
// echo 'Arguments are: ';
// print_r($args);
// echo '<br />';
if ($functionName != 'MKMATRIX') {
if ($this->_debugLog->getWriteDebugLog()) {
krsort($argArrayVals);
$this->_debugLog->writeDebugLog('Evaluating ', self::_localeFunc($functionName), '( ', implode(self::$_localeArgumentSeparator . ' ', PHPExcel_Calculation_Functions::flattenArray($argArrayVals)), ' )');
}
}
// Process each argument in turn, building the return value as an array
// if (($argCount == 1) && (is_array($args[1])) && ($functionName != 'MKMATRIX')) {
// $operand1 = $args[1];
// $this->_debugLog->writeDebugLog('Argument is a matrix: ', $this->_showValue($operand1));
// $result = array();
// $row = 0;
// foreach($operand1 as $args) {
// if (is_array($args)) {
// foreach($args as $arg) {
// $this->_debugLog->writeDebugLog('Evaluating ', self::_localeFunc($functionName), '( ', $this->_showValue($arg), ' )');
// $r = call_user_func_array($functionCall,$arg);
// $this->_debugLog->writeDebugLog('Evaluation Result for ', self::_localeFunc($functionName), '() function call is ', $this->_showTypeDetails($r));
// $result[$row][] = $r;
// }
// ++$row;
// } else {
// $this->_debugLog->writeDebugLog('Evaluating ', self::_localeFunc($functionName), '( ', $this->_showValue($args), ' )');
// $r = call_user_func_array($functionCall,$args);
// $this->_debugLog->writeDebugLog('Evaluation Result for ', self::_localeFunc($functionName), '() function call is ', $this->_showTypeDetails($r));
// $result[] = $r;
// }
// }
// } else {
// Process the argument with the appropriate function call
if ($passCellReference) {
$args[] = $pCell;
}
if (strpos($functionCall, '::') !== FALSE) {
$result = call_user_func_array(explode('::', $functionCall), $args);
} else {
示例15: SUMXMY2
/**
* SUMXMY2
*
* @param mixed[] $matrixData1 Matrix #1
* @param mixed[] $matrixData2 Matrix #2
* @return float
*/
public static function SUMXMY2($matrixData1, $matrixData2)
{
$array1 = PHPExcel_Calculation_Functions::flattenArray($matrixData1);
$array2 = PHPExcel_Calculation_Functions::flattenArray($matrixData2);
$count1 = count($array1);
$count2 = count($array2);
if ($count1 < $count2) {
$count = $count1;
} else {
$count = $count2;
}
$result = 0;
for ($i = 0; $i < $count; ++$i) {
if (is_numeric($array1[$i]) && !is_string($array1[$i]) && (is_numeric($array2[$i]) && !is_string($array2[$i]))) {
$result += ($array1[$i] - $array2[$i]) * ($array1[$i] - $array2[$i]);
}
}
return $result;
}