Reputation: 443
I have some fields, that send me $POST on submit. I want to get one value, but I can't, maybe I'm just blind, but for me that's impossible what I see here. PHP:
$i = 0;
$ok = Yii::$app->request->post("Presentations");
$ok2 = $ok[$i]['place_name'];
var_dump($ok);
var_dump($ok2);
$i++;
First var_dump shows me what expected:
array (size=8)
0 =>
array (size=11)
'gen_status_chechbox' => string '1' (length=1)
'name' => string 'F17011201' (length=9)
'presenter_id' => string '2' (length=1)
'presentation_assistants_ids' =>
array (size=1)
0 => string '1' (length=1)
'date' => string '2017-01-12' (length=10)
'time' => string '12:00' (length=5)
'place_id' => string '50' (length=2)
'place_name' => string '0' (length=1)
'place_city' => string '0' (length=1)
'place_street' => string 'a' (length=1)
'place_post_code' => string '00-000' (length=6)
1 =>
array (size=10)
'gen_status_chechbox' => string '1' (length=1)
'name' => string 'F17011202' (length=9)
'presenter_id' => string '2' (length=1)
'presentation_assistants_ids' =>
array (size=1)
0 => string '1' (length=1)
'date' => string '2017-01-12' (length=10)
'time' => string '12:00' (length=5)
'place_name' => string 'juz' (length=3)
'place_city' => string 'nie' (length=3)
'place_street' => string 'wiem' (length=4)
'place_post_code' => string '55-999' (length=6)
2 =>
array (size=11)
'gen_status_chechbox' => string '1' (length=1)
'name' => string 'F17011301' (length=9)
'presenter_id' => string '2' (length=1)
'presentation_assistants_ids' =>
array (size=1)
0 => string '1' (length=1)
'date' => string '2017-01-13' (length=10)
'time' => string '12:00' (length=5)
'place_id' => string '45' (length=2)
'place_name' => string '0' (length=1)
'place_city' => string '0' (length=1)
'place_street' => string 'a' (length=1)
'place_post_code' => string '00-000' (length=6)
And so on, up to 8, because I create 8 presentations. The second var_dump, shows me, no matter what, '0'. In second case, place_name is obviously 'juz', not '0'. I've been stuck with that for over 2 hours, and that's the point I came to have an apparent paradox, at least for me.
'0' is default value of 'place_name' input, but if $_POST has already different value, how can it appear later?
Upvotes: 0
Views: 45
Reputation: 5032
Okay, i see now.
I hope u have loop outside this code, BUT, u redefining $i
every loop iteration.
Take $i = 0;
before loop statement or use for()
like this:
$ok = Yii::$app->request->post("Presentations");
for($i = 0; $i < count($ok); $i++) {
$ok2 = $ok[$i]['place_name'];
var_dump($ok2);
}
Upvotes: 1