unset array

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

    unset array

    Hi all,

    I've created the following code:

    <?php

    session_start() ;
    ?>
    <FORM METHOD="POST" ACTION="prova.p hp">
    Add <b>Combinatio n</b><br><br>
    Element 1: <INPUT NAME="el1add" TYPE="TEXT">
    <BR>
    Element 2: <INPUT NAME="el2add" TYPE="TEXT">
    <br>
    <INPUT TYPE="SUBMIT" VALUE"Submit">
    </FORM>
    <br>
    <FORM METHOD="POST" ACTION="prova.p hp">

    Del <b>Combinatio n</b><br><br>
    Element 1: <INPUT NAME="el1del" TYPE="TEXT">
    <BR>
    Element 2: <INPUT NAME="el2del" TYPE="TEXT">
    <br>
    <INPUT TYPE="SUBMIT" VALUE"Submit">
    </FORM>
    <br><br>
    Combination<br> <br>
    <?php
    $_SESSION["combinatio ns"][] =
    ($_REQUEST["el1add"].$_REQUEST["el2add"]);
    unset($_SESSION["combinatio ns"][$_REQUEST["$el1del"]]);
    unset($_SESSION["combinatio ns"][$_REQUEST["$el2del"]]);
    print_r($_SESSI ON["combinatio ns"]);
    ?>

    I'd like to create an array combinations which includes all the
    combinations that I insert through the first form (add combinations).

    ref:
    $_SESSION["combinatio ns"][] = ($_REQUEST["el1add"].$_REQUEST["el2add"]);

    This works fine and is OK.
    Then, I'd like to delete from the array combinations all the
    combinations that I insert through the second form (del combinations).

    ref:
    unset($_SESSION["combinatio ns"][$_REQUEST["$el1del"]]);
    unset($_SESSION["combinatio ns"][$_REQUEST["$el2del"]]);

    This second part doesn't work.
    In particular, I want to delete all the elements of the array
    $_SESSION["combinatio ns"] that include $_REQUEST["$el1del"] or
    $_REQUEST["$el2del"] as text (not as key). I've some problem in doing it.
    Can you help me please?
    Many thanks.

    Cheers,
    Nico
  • Toby Inkster

    #2
    Re: unset array

    Nico wrote:
    unset($_SESSION["combinatio ns"][$_REQUEST["$el1del"]]);
    unset($_SESSION["combinatio ns"][$_REQUEST["$el2del"]]);
    ^^^
    Some extra $-signs in there.

    --
    Toby A Inkster BSc (Hons) ARCS
    Contact Me ~ http://tobyinkster.co.uk/contact

    Comment

    Working...