Short syntax for array in PHP

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sebastian Deutsch

    Short syntax for array in PHP

    Hello,

    is there a shorter syntax for array beside array("one", "two"),
    something link {"one", "two"}?

    cheers

    sebastian
  • ZeldorBlat

    #2
    Re: Short syntax for array in PHP

    On Jul 11, 9:46 am, Sebastian Deutsch <spam...@9eleme nts.comwrote:
    Hello,
    >
    is there a shorter syntax for array beside array("one", "two"),
    something link {"one", "two"}?
    >
    cheers
    >
    sebastian
    Not that I know of.

    What's wrong with the array("one", "two") syntax? Your proposed { }
    syntax is only shorted by the word "array" -- and the more items you
    have in the array the less significant it becomes.

    Comment

    • ZeldorBlat

      #3
      Re: Short syntax for array in PHP

      On Jul 11, 9:46 am, Sebastian Deutsch <spam...@9eleme nts.comwrote:
      Hello,
      >
      is there a shorter syntax for array beside array("one", "two"),
      something link {"one", "two"}?
      >
      cheers
      >
      sebastian
      Actually, now that I thought about it more, you could write a function
      and shorten it to a single character. So something like this:

      function a() {
      $arr = func_get_args() ;
      return $arr;
      }

      $anArray = a('one', 'two');

      Of course you can't assign keys that way, though.

      Comment

      • David T. Ashley

        #4
        Re: Short syntax for array in PHP

        "Sebastian Deutsch" <spamboy@9eleme nts.comwrote in message
        news:f72mvv$n9a $1@news01.versa tel.de...
        >
        is there a shorter syntax for array beside array("one", "two"),
        something link {"one", "two"}?
        The only other syntax I'm aware of that may save you some typing is the
        automatic assignment of subscripts, i.e.

        $a[] = "I'm"; //$a[0] = "I'm"
        $a[] = "the"; //$a[1] = "the"

        Etc.

        But as far as the "array" keyword ... no meaningful shortcut I'm aware of.

        --
        David T. Ashley (dta@e3ft.com)
        http://www.e3ft.com (Consulting Home Page)
        http://www.dtashley.com (Personal Home Page)
        http://gpl.e3ft.com (GPL Publications and Projects)


        Comment

        Working...