Nebojsa Komnenovic Nebojsa Komnenovic - 4 years ago 73
PHP Question

I want to get a string out of the posted array

I have a situation with getting the array from method = POST and I couldn't get the string that I want.
I post:

array(5) { 'family' => string(6) "single" 'gender' => string(1) "m" 'birthdate' => string(10) "13-03-1984" 'postalcode' => string(6) "2014GC" 'street_number' => string(1) "5" }

This is input field that I need from the form.

<input id="huisnummer" class="form-control input-lg" type="text" data-autotab-min-length="1" data-autotab="true" autocomplete="off" name="general[street_number]" data-val-min-value="0" data-val-min="" data-val-streetnumber="Voer een geldig huisnummer in" data-val-streetnumber-postalcode="general[postalcode]" maxlength="5" data-val="true" data-val-required="Vul alstublieft uw huisnummer in" tabindex="4" aria-required="true" aria-invalid="false">

Fifth element
'street_number' => string(1) "5"
comes from this input field.

Already tried scenarios:

$value = ($_POST['general[4]']); $value = ($_POST['general\\[street_number\\]']);

Do you think the best solution is implode and explode ?

Answer Source

That's not how one takes an element from a multidimensional array.

Instead of:

$value = ($_POST['general[street_number]']);

Use this:

$value = $_POST['general']['street_number'];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download