Jump to content

Archived

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

killerb

Repeating a process on a list of vars, like array_walk

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.

Share this post


Link to post
Share on other sites
This sample (using array_map) will work for you:
[code]<?php
$tl="1"; $tw="2"; $ew="3";
$arr=array($tl,$tw,$ew);
$b=array_map("addit", $arr);
print_r($b);
function addit($val) { return 'X'.$val; }
?>
[/code]

Share this post


Link to post
Share on other sites

×

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.