Slicing a multi-dimensional PHP array across one of its elements

后端 未结 10 933
再見小時候
再見小時候 2020-12-28 15:51

Say for example you just queried a database and you recieved this 2D array.

$results = array(
    array(\'id\' => 1, \'name\' => \'red\'  , \'spin\' =&         


        
10条回答
  •  悲哀的现实
    2020-12-28 16:35

    I did more research on this and found that ruby and prototype both have a function that does this called array_pluck,2. It's interesting that array_map has a second use that allows you to do the inverse of what i want to do here. I also found a PHP class someone is writing to emulate prototypes manipulation of arrays.

    I'm going to do some more digging around and if I don't find anything else I'll work on a patch to submit to the internals@lists.php.net mailing list and see if they will add array_pluck.

提交回复
热议问题