Professional Web Applications Themes

in the middle of shift and pop - PHP Development

is it possible to remove an element of an indexed array such as this exemple $A = array('a', 'b', 'c', 'd', 'e', 'f'); in a way that we can optain this result : $A = array('a', 'b', 'd', 'e', 'f'); something like that perhaps ? array_remove($A, 2); If such a function does not exists, what would be the more efficient way to do so a lot of time on very big arrays ?...

  1. #1

    Default in the middle of shift and pop

    is it possible to remove an element of an indexed array such as this exemple
    $A = array('a', 'b', 'c', 'd', 'e', 'f');
    in a way that we can optain this result :
    $A = array('a', 'b', 'd', 'e', 'f');

    something like that perhaps ?
    array_remove($A, 2);

    If such a function does not exists, what would be the more efficient way to
    do so a lot of time on very big arrays ?


    Decapode Azur Guest

  2. #2

    Default Re: [PHP] in the middle of shift and pop

    On Wed, 20 Aug 2003 00:25:32 +0200
    Decapode Azur <blue_prawntuxfamily.org> wrote:
    > is it possible to remove an element of an indexed array such as this
    > exemple
    > $A = array('a', 'b', 'c', 'd', 'e', 'f');
    > in a way that we can optain this result :
    > $A = array('a', 'b', 'd', 'e', 'f');
    >
    > something like that perhaps ?
    > array_remove($A, 2);
    >
    > If such a function does not exists, what would be the more efficient
    > way to do so a lot of time on very big arrays ?
    unset(array[x]);
    >
    >
    >
    > --
    > PHP General Mailing List ([url]http://www.php.net/[/url])
    > To unsubscribe, visit: [url]http://www.php.net/unsub.php[/url]
    >
    >
    >

    --
    Andu
    Andu Guest

  3. Moderated Post

    Default Re: [PHP] in the middle of shift and pop

    Removed by Administrator
    David Otton Guest
    Moderated Post

  4. #4

    Default Re: [PHP] in the middle of shift and pop

    Well, if you knew (for instance) that $A[2] should be removed then you
    could do something like:

    <?php
    foreach ($A as $key => $value)
    {
    if ($key < 2)
    { $B[$key] = $value; }
    elseif ($key > 2)
    { $B[($key - 1)] = $value; }
    }
    ?>

    Modify the above code as needed...

    -Dan

    On Tue, 2003-08-19 at 22:25, Decapode Azur wrote:
    > is it possible to remove an element of an indexed array such as this exemple
    > $A = array('a', 'b', 'c', 'd', 'e', 'f');
    > in a way that we can optain this result :
    > $A = array('a', 'b', 'd', 'e', 'f');
    >
    > something like that perhaps ?
    > array_remove($A, 2);
    >
    > If such a function does not exists, what would be the more efficient way to
    > do so a lot of time on very big arrays ?
    >
    >
    Dan Anderson Guest

  5. #5

    Default Re: [PHP] in the middle of shift and pop

    > If you unset an array that isn't associative, will that mean there will
    > be a gap in the numbers?
    Yes the items are grabed by their index.
    I'm using those arrays to manipulate 3D geometric shapes,
    (either vrml/x3d, OpenGL, POV and other ones**)
    so cartesian coordinates are first referenced in a first array,
    and then faces (facets?) are build giving the index of 3 (or more) points,
    so the index need to be the good one and not on a null or the next value.
    > Or will PHP realize "OK I need to change the numbers indexing the other
    > elements"?
    ** as PHP is a high level language I can write very quickly and very easily
    scripts to make manipulations on my 3D meshes, but the problem is that it
    often takes more than an hour to execute, so I realy need to learn about
    writing efficient code and optimizing PHP...

    [snip]----------8<-------------------
    > I'm compelled to ask *why* you want that result. In most cases it makes
    > no difference to your coding, so the only real reason I can see is a
    > somewhat obsessive desire for neatness!
    Perhaps there is a better way to grab the good points to build the faces,
    but I did not find another solution yet.
    If you know about another better issue to resolve this problem, please let
    me know about it.


    Decapode Azur Guest

Similar Threads

  1. When to USE shift or _
    By Colin Johnstone in forum PERL Beginners
    Replies: 4
    Last Post: September 9th, 05:25 PM
  2. Shift + 3 = # ???
    By wayne_l_hooper@adobeforums.com in forum Adobe Indesign Windows
    Replies: 9
    Last Post: May 11th, 09:55 AM
  3. About Shift
    By Paul Kraus in forum PERL Beginners
    Replies: 0
    Last Post: August 22nd, 03:57 PM
  4. [PHP] in the middle of shift and pop
    By Mike Ford in forum PHP Development
    Replies: 2
    Last Post: August 21st, 04:24 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139