Jump to content

Repeating a process on a list of vars, like array_walk


killerb

Recommended Posts

Does anyone know a function that does this? I have just found a use for it, while making a simple program to calculate timber lengths for making a box.

I take L,w,h, thickness and timberWidth, then do the various equations, then with the resultVars, I want to send them through number_format() before displaying them.

My function uses global vars. If I had used an array, I could do array_walk, but I have vars.

I tried a few things:
[code]
<?php

$arr=array($tl,$tw,$ew,$eh,$sl,$sh);//etc
array_walk($arr,'number_format');
// doesnt work

$arr=array(&$tl,&$tw,&$ew,&$eh,&$sl,&$sh);//etc
array_walk($arr,'number_format');
// Nope.

array_walk(array($tl,$tw,$ew,$eh,$sl,$sh),'number_format');
// E_ERROR

array_walk(($tl,$tw,$ew,$eh,$sl,$sh),'number_format');
// E_ERROR

?>
[/code]

Is there actually a way to do it so the array_walk loop updates all referenced vars?

No results from searching.

Cheers.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.