Created
October 16, 2017 17:28
-
-
Save wordpress-lab/773c3a5c771db2a58dbd375f9e739373 to your computer and use it in GitHub Desktop.
php array group best
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$array = array( | |
array( | |
"type" => "a", | |
"value" => 1 | |
), | |
array( | |
"type" => "a", | |
"value" => 2 | |
), | |
array( | |
"type" => "a", | |
"value" => 3 | |
), | |
array( | |
"type" => "b", | |
"value" => 1 | |
), | |
array( | |
"type" => "b", | |
"value" => 2 | |
),array( | |
"type" => "b", | |
"value" => 4 | |
), | |
array( | |
"type" => "f", | |
"value" => 2 | |
) | |
); | |
foreach ($array as $element) | |
$newArray[$element["type"]][] = $element["value"]; | |
var_export($newArray); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment