echo a variable from a multidimentional array outside a function -


the code below works string value not when try access variable directly. data being accessed table @ http://webrates.truefx.com/rates/connect.html?f=html code strips of tags , put in array $row0 , puts in function. can't out. function simplified question. intend concatenate of variables inside function once find out i'm doing wrong.

$row0 = array();  include "scrape/simple_html_dom.php"; $url = "http://webrates.truefx.com/rates/connect.html?f=html"; $html = new simple_html_dom(); $html->load_file($url); foreach ($html->find('tr') $i => $row) {     foreach ($row->find('td') $j => $col) {         $row0[$i][$j]= strip_tags($col);     } }  myarray($row0); //table stripped of tags  function myarray($arr) {     $a = 'hello';         //$arr[0][0]; hello come out not variable     $b = $arr[1][0];     $r[0] = $a;     $r[1] = $b;     //echo $r[1]; if //'s removed 1 can see proper value here not outside function.     return $r; }  $arraytoecho = myarray($arr);  echo $arraytoecho[0]; // echo "first" 

i have tried suggestions here:

http://stackoverflow.com/questions/3451906/multiple-returns-from-function http://stackoverflow.com/questions/5692568/php-function-return-array 

suggestion appreciated please , more info available if required. thank viewing.

you need innertext of $col in loop. this:

$row0[$i][$j]= $col->innertext; 

the next thing is:

myarray($row0); 

this call correctly return parsed array; try echoing , you'll see. when this:

$arraytoecho = myarray($arr); 

...you're referencing $arr local variable (a parameter, actually) inside function myarr. meant this:

$arraytoecho = myarray($row0); 

hope helps!

update

look, show happens when call function:

function-call


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -