Re: finding a variables name

From: Date: Tue, 15 May 2001 04:34:13 +0000
Subject: Re: finding a variables name
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-52805@lists.php.net to get a copy of this message
CC Zona wrote:
Can you give an example of code in which you'd be doing this?
Ok here is what I am trying to acheive, basically turning a php array into a javascript array, note this is untested and most likley won't work :-) Where $array_name I need the same name as the functions first and only argument $array, so I need the name of the array that has been passed to the function. /////////////////////////////////////////////////// function makeJSArray($array) {
      $out = "$array_name = new Array(";
      $size = sizeof($array);
      $i = 0;
      while ( list($key, $val) = each($array) ) {
      $out .= "$array_name[$key] = $val";
      if ($size != $i - 1)
      $out .= ",";
      }
      $out .= ");";
      return $out;
} ///////////////////////////////////////////////// Thanks, Joseph

« previous php.general (#52805) next »