phoenixx Posted August 4, 2008 Share Posted August 4, 2008 I've "scraped" some data from one of my other sites and need to assign dynamically increasing variables: Heres some sample code. In the end, each output row will have $variable1 = $k . " " . $v; $variable2 = $k . " " . $v; etc... $data = @file_get_contents("https://XXX/index.php?inputEmailHandle=XXX", "r"); ; preg_match_all('/<input.*?name="([^"]*)".*?value="([^"]*)"/is',$data,$out); $d = array_combine($out[1], $out[2]); //$insert_into = array(); foreach($d as $k=>$v){ echo $variablevariable . " = " . $k . " = " . $v . "<br>"; } Link to comment https://forums.phpfreaks.com/topic/118150-variable-variables/ Share on other sites More sharing options...
DarkWater Posted August 4, 2008 Share Posted August 4, 2008 Ummm...what? O_O I don't understand the question. I don't see a question, actually. Link to comment https://forums.phpfreaks.com/topic/118150-variable-variables/#findComment-607847 Share on other sites More sharing options...
phoenixx Posted August 4, 2008 Author Share Posted August 4, 2008 The output should be something like $variable1 = [output from 1st foreach loop] $variable2 = [output from 2nd foreach loop] but the $variable should by incrementing by one number each time in a loop until the foreach loop is done Link to comment https://forums.phpfreaks.com/topic/118150-variable-variables/#findComment-607859 Share on other sites More sharing options...
wildteen88 Posted August 4, 2008 Share Posted August 4, 2008 Example of variable variable $str = 'hello'; ${$str . 'world'} = 'hi'; echo $helloworld; // outputs hi In your case you'll need to implement a counter. However it'll be better to use an array instead (after all this is what their there for) Link to comment https://forums.phpfreaks.com/topic/118150-variable-variables/#findComment-607864 Share on other sites More sharing options...
DarkWater Posted August 4, 2008 Share Posted August 4, 2008 Why not make an array...? Link to comment https://forums.phpfreaks.com/topic/118150-variable-variables/#findComment-607865 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.