tags:

views:

62

answers:

1

I want to making loop with xpath() with this function:

function rs(){

$rs = array();
$cities = array("city1", "city2", "city3", "city4", "city5",
    "city6", "city7", "city8");
foreach ($cities as $value) {

    $rs[] = $xmls->xpath("area[city= '$value']");

}
return $rs; }

$rs = rs();

Edit:

function meteor(){

$request_url = "http://meteoroloji.gov.tr/FTPDATA/analiz/sonSOA.xml";
$xml = simplexml_load_file($request_url) or die("feed not loading");
return $xml;}
$xmls = meteor();

with print_r($rs); I have Fatal error: Call to a member function xpath() on a non-object. Is my function wrong? (Im not familliar with OOP) Thanks in advance

+2  A: 

$xmls is not in scope, as simple as that. Pass it as an argument (rs($xmls)), or set it as an attribute if this is a method from a class rather then a standalone function (and it if that would be more logical).

Wrikken
I have tried the argumant before, Its not working too.
phpExe
Provide the example of the function with an argument, and the code you use to call the function, and maybe we can see more. As it stand _"it's not working too"_ isn't a problem description that is of any use to us.
Wrikken
@Wrikken; Thanks for help, With "it's not working too" means that I have the same error with argument. With global $xmls there is no error. I want to know why argument doesnt work in this OOP case.
phpExe
@phpExe: I refer you to my previous statement: _"Provide the example of the function with an argument, and the code you use to call the function, and maybe we can see more"_, without it this is just inane guesswork :)
Wrikken
@Wrikken; I have edited my question.
phpExe
So, what happens if you alter the `function res(){` to `function rs($xmls){`, and call `$rs = rs(meteor());`?
Wrikken
Fatal error: Call to a member function xpath() on a non-object
phpExe
Could you pastebin your current code somewhere so I could check locally? I find this all very odd.
Wrikken
@Wrikken, your answer has solved my problem. Thank you very much.
phpExe