Jump to content


Photo

calling static arrays (like self::mSomeArray['some_value'])


  • Please log in to reply
2 replies to this topic

#1 swap

swap
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 21 October 2006 - 09:50 AM

Hery dudes,

Trying to call a static array in my formclass, but it doesn't work.

 <?php
    class Nonse(){
          public static $mArray=array('var_1', 'var_2', 'var_2');


           public static CallArrayVal($c){
                   return self::mArray[$c];
           }
  echo Nonse::CallArrayVal(1);
  echo Nonse::mArray[1];
?>

None of the above examples work, and php tells me that it can't find the variables $mArray.
Can someone please help me out here?

    Many tnks.


#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 21 October 2006 - 10:43 AM

<?php
    class Nonse {
          public static $mArray=array('var_1', 'var_2', 'var_2');


           public static function CallArrayVal($c){
                   return self::$mArray[$c];
           }
    }
    
  
  echo Nonse::CallArrayVal(1);
  echo '<br />';
  echo Nonse::$mArray[1];
  echo '<br />';
  
  $obj = new Nonse;
  echo $obj->CallArrayVal(1);
?>

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 swap

swap
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 21 October 2006 - 03:44 PM

Thans dude, didn't know that yet.

;D




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users