# simpleXML variables in functions

**URL:** <https://forum.kirupa.com/t/simplexml-variables-in-functions/312251>\
**Category:** programming\
**Created:** [July 29, 2010, 6:23am UTC](https://forum.kirupa.com/t/simplexml-variables-in-functions/312251 "2010-07-29T06:23:46Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![spyderfx](https://avatars.discourse-cdn.com/v4/letter/s/c2a13f/32.png) [@spyderfx](https://forum.kirupa.com/u/spyderfx)\
**Post date:** [July 29, 2010, 6:23am UTC](https://forum.kirupa.com/t/simplexml-variables-in-functions/312251/1 "2010-07-29T06:23:46Z")

</div>

I have this code on one part of an html page

```auto

<?php
    
    
    $file = 'events.xml';
    $xml = simplexml_load_file($file);
    
    function popCal(){
        echo $xml->day->event[0]->name;
           }
    
    echo $xml->day->event[0]->name;
    
    
    $day=array(0 => 0, 1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6, 7 => 7);

    
    
    
?> 

```

and this code in a table cell somewhere else in same page

```auto

<?php popCal(); ?>

```

If I put a simple statement like echo “Foo”; in popCal function it works. If I put echo $xml-\>day-\>event[0]-\>name; outside the function, it works. Is there any obvious reason why this shouldn’t work inside the function popCal()?
