modification tableau multidimensionnel
Bonjour
Je cherche à transformer un tableau unidimentionnel en multidimentionnel en fonction de clés dynamiques
Le tableau d'origine
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
$arr = array(
0 => array(
"attributs_id" => "9",
"libelle"=> "Checkbox",
"famille" => "Choix",
"slug" => "input_checkbox"
),
1 => array(
"attributs_id" => "10",
"libelle"=> "Input",
"famille" => "Texte",
"slug" => "input"
),
2 => array(
"attributs_id" => "17",
"libelle"=> "Zone de texte",
"famille" => "Texte",
"slug" => "textearea"
)
); |
Le tableau des clés
Code:
1 2 3 4 5
|
$arg_list = array(
0 => "famille",
1 => "attributs_id"
); |
Résultat attendu
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
$tResult = array( "Choix" =>
array( 9 =>
array(
"attributs_id" => "9",
"libelle"=> "Checkbox",
"famille" => "Choix",
"slug" => "input_checkbox"
)
),
"Texte" =>
array( 10 =>
array(
"attributs_id" => "10",
"libelle"=> "Input",
"famille" => "Texte",
"slug" => "input"
),
17 =>
array(
"attributs_id" => "17",
"libelle"=> "Zone de texte",
"famille" => "Texte",
"slug" => "textearea"
)
),
); |
Test non concluant
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
foreach($arr as $row)
{
$result = 'tResult';
foreach($arg_list as $v)
{
$result .= "['".$row[$v]."']";
}
$$result = $row;
}
var_dump($tResult);
//affichage du var_dump : Array(0) |
Merci par avance de votre aide