0

I have a form with this entry

<input type="checkbox" name="option[repassage]" id="options1" value="10.00"> Repassage 30 mn
<input type="checkbox" name="option[frigo]" id="options2" value="5.00"> Frigo 30 mn

With php i do this to get all the options and i put them in an array but i can not get the right values for 'titre_option' and 'prix_option' !!!

if (isset($_POST['option'])) {
    foreach ( $_POST['option'] as $key => $value ) {
        $_SESSION['option'][] = array('titre_option' => $_POST['option'][$key], 'prix_option' => $_POST['option'][$value]);
    }
}

// What i get
Array
(
    [0] => Array
        (
            [titre_option] => 10.00
            [prix_option] => 
        )

    [1] => Array
        (
            [titre_option] => 5.00
            [prix_option] => 
        )

)

// What i need
Array
(
    [0] => Array
        (
            [titre_option] => repassage
            [prix_option] => 10.00
        )

    [1] => Array
        (
            [titre_option] => frigo
            [prix_option] => 5.00
        )

)

Thank you for your help...

1 Answer 1

1

Change this line

$_SESSION['option'][] = array('titre_option' => $_POST['option'][$key], 'prix_option' => $_POST['option'][$value]);

To this

$_SESSION['option'][] = array('titre_option' => $key, 'prix_option' => $value);

Because of the foreach loop, you already have the right variables, and don't need to get them again from the array.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.