killerb Posted August 6, 2006 Share Posted August 6, 2006 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);//etcarray_walk($arr,'number_format');// doesnt work$arr=array(&$tl,&$tw,&$ew,&$eh,&$sl,&$sh);//etcarray_walk($arr,'number_format');// Nope.array_walk(array($tl,$tw,$ew,$eh,$sl,$sh),'number_format');// E_ERRORarray_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. Quote Link to comment Share on other sites More sharing options...
ronverdonk Posted August 6, 2006 Share Posted August 6, 2006 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] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.