Re: Re: How to re-order an array

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



jekillen wrote:
[···]
Well, I asked you for the actual (JS) code you're using (the one that didn't work in all the intended browsers), that way someone might be able to help you (I will if I can)

Array.push(), Array.pop(), Array.shift(), Array.unshift().

Ok, so what are your intended browsers? According to what I found, these functions are part of ECMAS 3 standard, and are available in FF 1.0, Netscape 4, e IE 5.5 (unshift until IE 6) --as always, M$ gives the problems.

	You might try to implement them yourself, such as...
  // "object detection" for shift function
  if ( undefined == Array.prototype.shift ) {
    Array.prototype.shift = function( ) {
      var  val = this[0];
      for ( var  i = 0;  i < this.length - 1;  i ++ ) {
        this[i] = this[i + 1];
      }
      this.length --;
      return  val;
    } // shift()
  }
  // "object detection" for unshift function
  if ( undefined == Array.prototype.unshift ) {
    Array.prototype.unshift = function( ) {
      var  args = arguments,
           len  = this.length + args.length;
      this.length = len;
      for ( var  i = len - 1;  i >= args.length;  i -- ) {
        this[i] = this[i - args.length];
      }
      for ( i = 0;  i < args.length;  i ++ ) {
        this[i] = args[i];
      }
    } // unshift()
  }

  var  x = new Array( 'z', 'b', 'c', 'd' ),
       y = null;
  document.write("&rarr; "+ x.toString() +"<br />\n");
  y = x.shift();
  x.unshift('A', 'a');
  document.write("&rArr; "+ y +" &rArr; ["+ x.toString() +"]");

Note: tested only in Fx 1.5.0.3 (as _shift & _unshift) with secuential
      arrays (and not associative/hash arrays)

I thought that if I used Ajax, php could use its push and pop, shift and unshift functions, but not all browsers support the asymetric requests.

Well, that seems too complex to solve your problem, but if you want to try it, you may use the same "object detection" above and implement those methods with PHP (e.g. unshift in IE 5.5, or all of the functions you mentioned in IE 5.0)

I do screen in the server. But I force the user to have javascript enabled and force the form to submit using javascipt, and have a unique id as a javascript variable that is sent along with the form in a hidden field to identify the source of the form data. I never use get requests unless they are appended to anchor tags, even in forms that are not processed by the server (I.E. running javascript code with user supplied arguments to functions via form fields, in which case an action attribute
isn't even necessary, and like wise a post or get method).

It's basically the same problem, you shouldn't rely on javascript for your page to actually do something. If I don't have JS enabled (for whatever the reason) I won't be able to do anything on it. JS should be used only to _add or complement_ functionality.
--
Atentamente / Sincerely,
J. Rafael Salazar Magaña

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux