Professional Web Applications Themes

how to make a global scope array - PHP Development

<20030725224852.1123.qmailpb1.pair.com> Jack Lee: > //I have an array a[] like this: > > <?php > $a[]=0; > > //How to define and use it in a function like this? > > function myfunc(something) > { > echo $a[0]; //got error here!!!! Notice: Undefined variable: > > } > >> > //Thanks for any help.!!! global $a;...

  1. #1

    Default Re: [PHP] how to make a global scope array

    <20030725224852.1123.qmailpb1.pair.com>
    Jack Lee:
    > //I have an array a[] like this:
    >
    > <?php
    > $a[]=0;
    >
    > //How to define and use it in a function like this?
    >
    > function myfunc(something)
    > {
    > echo $a[0]; //got error here!!!! Notice: Undefined variable:
    >
    > }
    >
    >>
    > //Thanks for any help.!!!
    global $a;


    Comex Guest

  2. #2

    Default Re: [PHP] how to make a global scope array

    Hello,

    This is a reply to an e-mail that you wrote on Fri, 25 Jul 2003 at
    23:51, lines prefixed by '>' were originally written by you.
    > <20030725224852.1123.qmailpb1.pair.com>
    > Jack Lee:
    > > //I have an array a[] like this:
    > > <?php
    > > $a[]=0;
    > > //How to define and use it in a function like this?
    > > function myfunc(something)
    > > {
    > > echo $a[0]; //got error here!!!! Notice: Undefined
    variable:
    > > }
    > > //Thanks for any help.!!!
    > global $a;
    ... or echo $GLOBALS['a'][0];

    David.

    --
    phpmachine :: The quick and easy to use service providing you with
    professionally developed PHP scripts :: [url]http://www.phpmachine.com/[/url]

    Professional Web Development by David Nicholson
    [url]http://www.djnicholson.com/[/url]

    QuizSender.com - How well do your friends actually know you?
    [url]http://www.quizsender.com/[/url]
    (developed entirely in PHP)
    David Nicholson Guest

  3. #3

    Default Re: [PHP] how to make a global scope array

    * Thus wrote Comex (ngxemoc.cjb.net):
    > <20030725224852.1123.qmailpb1.pair.com>
    > Jack Lee:
    > > //I have an array a[] like this:
    > >
    > > <?php
    > > $a[]=0;
    > >
    > > //How to define and use it in a function like this?
    > >
    > > function myfunc(something)
    > > {
    > > echo $a[0]; //got error here!!!! Notice: Undefined variable:
    > >
    > > }
    > >
    > >>
    > > //Thanks for any help.!!!
    >
    > global $a;
    Ouch!

    Sometimes I wish global didn't exist

    Curt
    --
    "I used to think I was indecisive, but now I'm not so sure."
    Curt Zirzow Guest

  4. #4

    Default Re: [PHP] how to make a global scope array

    Hello,

    This is a reply to an e-mail that you wrote on Sat, 26 Jul 2003 at
    00:50, lines prefixed by '>' were originally written by you.
    > Ouch!
    > Sometimes I wish global didn't exist
    Yes, it can be better to pass in a variable (by reference if you need
    to write to it from within a function and not have it as the value
    that you return), e.g.

    function doSomething(&$a){
    $a = 20;
    return true; // to signify success
    }

    $a = 10;
    doSomething($a);
    echo $a; // prints 20


    --
    phpmachine :: The quick and easy to use service providing you with
    professionally developed PHP scripts :: [url]http://www.phpmachine.com/[/url]

    Professional Web Development by David Nicholson
    [url]http://www.djnicholson.com/[/url]

    QuizSender.com - How well do your friends actually know you?
    [url]http://www.quizsender.com/[/url]
    (developed entirely in PHP)
    David Nicholson Guest

  5. #5

    Default how to make a global scope array

    //I have an array a[] like this:

    <?php
    $a[]=0;

    //How to define and use it in a function like this?

    function myfunc(something)
    {
    echo $a[0]; //got error here!!!! Notice: Undefined variable:

    }

    ?>
    //Thanks for any help.!!!


    Jack Lee Guest

  6. #6

    Default Re: [PHP] how to make a global scope array

    It works! Thanks guys!

    "David Nicholson" <medjnicholson.com> wrote in message
    news:8f831227b0eb6c6d09a0555531365933home.djnicho lson.com...
    Hello,

    This is a reply to an e-mail that you wrote on Fri, 25 Jul 2003 at
    23:51, lines prefixed by '>' were originally written by you.
    > <20030725224852.1123.qmailpb1.pair.com>
    > Jack Lee:
    > > //I have an array a[] like this:
    > > <?php
    > > $a[]=0;
    > > //How to define and use it in a function like this?
    > > function myfunc(something)
    > > {
    > > echo $a[0]; //got error here!!!! Notice: Undefined
    variable:
    > > }
    > > //Thanks for any help.!!!
    > global $a;
    ... or echo $GLOBALS['a'][0];

    David.

    --
    phpmachine :: The quick and easy to use service providing you with
    professionally developed PHP scripts :: [url]http://www.phpmachine.com/[/url]

    Professional Web Development by David Nicholson
    [url]http://www.djnicholson.com/[/url]

    QuizSender.com - How well do your friends actually know you?
    [url]http://www.quizsender.com/[/url]
    (developed entirely in PHP)


    Jack Lee Guest

Similar Threads

  1. Scope problem?: Global array assignment
    By r in forum PHP Development
    Replies: 2
    Last Post: April 29th, 08:33 PM
  2. Problem with sessions (in global scope vs class scope)
    By Yoyoma_2 in forum PHP Development
    Replies: 5
    Last Post: November 17th, 02:03 PM
  3. [PHP] global scope issue
    By Shawn McKenzie in forum PHP Development
    Replies: 2
    Last Post: August 14th, 01:29 AM
  4. global scope issue
    By Ivo Fokkema in forum PHP Development
    Replies: 3
    Last Post: August 13th, 06:07 PM
  5. Replies: 0
    Last Post: July 17th, 09:23 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139