Thread: evalArray()
View Single Post
  #1  
Old 05-28-2011, 03:19 PM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
evalArray()

I've written a small function that basically applies a calculation to all elements of an array using Zero's eval function.

Here it is:
PHP Code:
function evalArray(arrev) {
  if (
arr[0].size() == 0)
    
arr = { arr };
  
  
// evaluate all array elements
  
temp.nArr = new[arr[0].size()];
  for (
temp.0arr[0].size(); i++) {
    
temp.eva ev;
    for (
temp.0eva.size(); k++)
      for (
temp.0arr.size(); l++)
        if (
eva[k] == "E" l)
          
eva[k] = arr[l][i];
    
    
nArr[i] = evalPost(eva);
  }
  
  return 
nArr;

The first argument is either a single array of values to use in the calculations or an array of multiple arrays holding values (if you want to use more than one). The function will return an array the size of the (first) value array, holding all the solutions.

The second argument is your formula in post-fix notation (more on that in Zero's thread). In this array you can use E0, E1, E2 and so on to refer to the current array element of the specific array (starting at 0, obviously) depending on how many arrays you've given to the function.


Example:
PHP Code:
temp.a1 = { 12};
temp.a2 = { 45};
echo(
evalArray({ a1a2 }, { "E0""E1""+"2"*" })); // returns { 10, 14, 18 } 

Maybe this is useful for some of you guys. I've written it for a project of mine.
Reply With Quote