Skip to content

Instantly share code, notes, and snippets.

@wordpress-lab
Created October 16, 2017 17:28
Show Gist options
  • Save wordpress-lab/773c3a5c771db2a58dbd375f9e739373 to your computer and use it in GitHub Desktop.
Save wordpress-lab/773c3a5c771db2a58dbd375f9e739373 to your computer and use it in GitHub Desktop.
php array group best
$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