include with array

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Alexander Gausa

    include with array

    hi
    i want to include rows in an array using include. but this always ends with
    an error. any idea?

    $files=array(
    array(1,2,3),
    array(2,3,4),
    include "addon"
    array(4,5,6)
    }

    addon:
    <?php
    array(3,4,5),
    array(6,7,8),
    ?>

  • Duyet The Vo

    #2
    Re: include with array

    It doesn't work this way (not that I aware off :)
    include() can be used to include files.

    $files=array(
    array(1,2,3),
    array(2,3,4),
    array(4,5,6)
    }

    include "addon"

    $newarray = array_merge( $files, $addon );

    <?php

    $addon=array(ar ray(3,4,5),
    array(6,7,8),
    )
    ?>


    "Alexander Gausa" <ingga@gmx.de > wrote in message
    news:d10k85$pe6 $05$1@news.t-online.com...[color=blue]
    > hi
    > i want to include rows in an array using include. but this always ends
    > with
    > an error. any idea?
    >
    > $files=array(
    > array(1,2,3),
    > array(2,3,4),
    > include "addon"
    > array(4,5,6)
    > }
    >
    > addon:
    > <?php
    > array(3,4,5),
    > array(6,7,8),
    > ?>
    >[/color]


    Comment

    • Alvaro G. Vicario

      #3
      Re: include with array

      *** Alexander Gausa escribió/wrote (Sun, 13 Mar 2005 06:48:52 +0100):[color=blue]
      > i want to include rows in an array using include. but this always ends with
      > an error. any idea?
      >
      > $files=array(
      > array(1,2,3),
      > array(2,3,4),
      > include "addon"
      > array(4,5,6)[/color]

      Manual says:

      "When a file is included, parsing drops out of PHP mode and into HTML mode
      at the beginning of the target file, and resumes again at the end. For this
      reason, any code inside the target file which should be executed as PHP
      code must be enclosed within valid PHP start and end tags."

      Testing shows that this working code:

      <?php

      $foo=array(1, 2, 3);
      print_r($foo);

      ?>

      cannot be rewritten as:

      <?php

      $foo=array(1, ?><?php 2, 3);

      print_r($foo);

      ?>


      Parse error: parse error, expecting `')'' in C:\tmp\borrame. php on line 3

      I understand that you can't finish a PHP block in the middle of a sentence.


      --
      -+ Álvaro G. Vicario - Burgos, Spain
      +- http://www.demogracia.com (la web de humor barnizada para la intemperie)
      ++ Manda tus dudas al grupo, no a mi buzón
      -+ Send your questions to the group, not to my mailbox
      --

      Comment

      • Janwillem Borleffs

        #4
        Re: include with array

        Alexander Gausa wrote:[color=blue]
        > i want to include rows in an array using include. but this always
        > ends with an error. any idea?
        >
        > $files=array(
        > array(1,2,3),
        > array(2,3,4),
        > include "addon"
        > array(4,5,6)
        > }
        >[/color]

        addon:
        <?php
        $array = array(3,4,5);
        $array2 = array(6,7,8);
        ?>

        <?php
        include "addon";

        $files=array(
        array(1,2,3),
        array(2,3,4),
        $array,
        $array2,
        array(4,5,6)
        );
        ?>


        JW



        Comment

        • Jerry Sievers

          #5
          Re: include with array

          Alexander Gausa <ingga@gmx.de > writes:
          [color=blue]
          > hi
          > i want to include rows in an array using include. but this always ends with
          > an error. any idea?
          >
          > $files=array(
          > array(1,2,3),
          > array(2,3,4),
          > include "addon"
          > array(4,5,6)
          > }
          >
          > addon:
          > <?php
          > array(3,4,5),
          > array(6,7,8),
          > ?>
          >[/color]

          What you are trying to do here is employ include/require as if it were
          a macro. My understanding is that it can't be used this way.

          In fact your example can be made syntactically correct by putting a
          comma after the include statement but all you'll get as return value
          is either a 1 for success or false if the include failed.

          But the code in the included file must be a complete statement, not a
          fragment as you have shown above.

          Try something like the M4 macro processor if you have an absolute need
          for doing this.

          HTH

          --
          -------------------------------------------------------------------------------
          Jerry Sievers 305 854-3001 (home) WWW ECommerce Consultant
          305 321-1144 (mobile http://www.JerrySievers.com/

          Comment

          • Ramesh Thiruchelvam

            #6
            Re: include with array

            why don't you try ... :)

            $files[] = array(1,2,3);
            $files[] = array(2,3,4);
            include "addon"
            $files[] = array(4,5,6);

            addon:
            <?php
            $files[] = array(3,4,5);
            $files[] = array(6,7,8);
            ?>

            Comment

            • Chung Leong

              #7
              Re: include with array


              "Alexander Gausa" <ingga@gmx.de > wrote in message
              news:d10k85$pe6 $05$1@news.t-online.com...[color=blue]
              > hi
              > i want to include rows in an array using include. but this always ends[/color]
              with[color=blue]
              > an error. any idea?
              >
              > $files=array(
              > array(1,2,3),
              > array(2,3,4),
              > include "addon"
              > array(4,5,6)
              > }
              >
              > addon:
              > <?php
              > array(3,4,5),
              > array(6,7,8),
              > ?>
              >[/color]

              That works in PHP 3 but not not PHP 4. See
              http://www.php.net/manual/en/migration4.parser.php.


              Comment

              Working...