Edit report at http://bugs.php.net/bug.php?id=49671&edit=1

 ID:                 49671
 Updated by:         [email protected]
 Reported by:        whatchildisthis at gmail dot com
 Summary:            Change to first argument of array_map.
-Status:             Open
+Status:             Bogus
 Type:               Feature/Change Request
-Package:            Feature/Change Request
+Package:            *General Issues
 Operating System:   Windows 2003
 PHP Version:        5.3.0
 Block user comment: N
 Private report:     N

 New Comment:

It's your form that needs fixing, not PHP in this case. Just pass the
variables from the form with proper tags and you will get the arrays as
you wish.

Something like this:



<form method="post">

  <input name="invoice[0][name]">

  <input name="invoice[0][price]">

  <input name="invoice[1][name]">

  <input name="invoice[1][price]">

  <input type="submit">

</form>


Previous Comments:
------------------------------------------------------------------------
[2009-09-25 18:56:45] whatchildisthis at gmail dot com

Description:
------------
Based on the rise of web based applications, it is common to have
applications that allow a user to insert an indefinite number of rows of
data (such as an invoice, contact list).



It would be great to see array_map take an array of keys as the first
argument, also, so that it does the same thing as if the first argument
was null, but uses the first array as the keys of the maped arrays, much
like array_combine being called on each maped array after. This recycles
an already existing function to do something I thought it would already
be able to do without the callback.



PHP DATA GENERATED FROM HTML FORM OF AN INVOICE:

$_POST["Invoice"] = array(

  "Description" => array(

    "A widget",

    "A gadget"

  ),

  "Price" => array(

    '$1.00',

    '$3.00'

  ),

  "Units" => array(

    2,

    3

  )

);



NEW PHP CODE:

array_map(

  array("Description", "Price", "Units"),

  $_POST["Invoice"]["Description"],

  $_POST["Invoice"]["Price"],

  $_POST["Invoice"]["Units"]

);



NEW PHP RESULT:

array(

  0 => array(

    "Description" => "A widget",

    "Price" => "$1.00",

    "Units" => 2

  ),

  1 => array(

    "Description" => "A gadget",

    "Price" => "$3.00",

    "Units" => 3

  )

)





I don't think this feature would be difficult to implement and it would
be a great addition to array_map's functionality.



------------------------------------------------------------------------



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=49671&edit=1

Reply via email to