Sunday, 15 April 2012

php - Getting only first value in List() with static But full value with out static method -


itemprop = "text">

In my display () the method setting value using stable initPost () and using all prices get stable and stable value Get a single value ('email') method. When I am using var_dump () then everything is fine. I want to believe in my list. But I'm getting only the first string of each value. But when I do this (with the static method with getting full value in my list) What's the problem?

  Public function display () {echo "
"; Form :: initPost ()); // Start value var_dump (form :: getAll ()); // Getting all values ​​var_dump (form :: get ('email')); // Only email value list ($ name), $ email, $ pass, $ rps, $ phone) = form :: getAll (); // value to var_dump ($ name); // Listing on; Here's the problem. Receiving the first string only with the full name}  

This is my form class:

  class form {personal fixed $ value = array}; Public stable work initPost () {foreach ($ _ POST $ key = & gt; $ value) self: $ value [$ key] = $ value; } Public stable work getAll () {returns self :: $ value; } Get public stable work ($ value) {self: $ value = $ _POST [$ value]; Return self: $ value; }}  

// This is the output section

  var_dump (form :: getAll ()); // Getting all the value arrays (5) {["name"] = & gt; String (12) "Bristy Bela" ["Email"] = & gt; String (16) "bristi@gmail.com" ["pass"] = & gt; String (6) "123456" ["rpass"] = & gt; String (6) "123456" ["phone"] = & gt; String (6) "123456"} // Received email value var_dump (form :: get ('email')); String (16) "bristi@gmail.com" var_dump ($ name); // Only getting the first string with the full name But the full name string is descripted (1) "b"  

because By calling get ('email') you killed $ $ value array and set it up for your post request with a string with email field. By placing list () on a string, it keeps each letter of the string in your list and echoing the first item of your list will give you the first character.

You should not overwrite on your form: Instead of the array key from your form :: $ value, get this:

  Get public stable work ($ value) {Return array_key_exists ($ value, self :: $ value)? Auto :: $ value [$ value]: wrong; }  

Or at least set the requested index like this:

  get a public stable job ($ value) {self: $ value [$ Value] = $ _POST [$ value]; Return self: $ value [$ value]; }  

and you should not get the variable using the list () Please do this:

  $ name = form :: get (' Name '); $ Email = form :: find ('email'); $ Pass = form :: get ('pass'); $ Rpass = Form :: Mill ('ramp'); $ Phone = form :: find ('phone');  

Or just do this:

  $ all = form :: getAll (); Echo $ all ['email']; Echo $ all ['phone']; // and so on  

No comments:

Post a Comment