Skip to content

Instantly share code, notes, and snippets.

@bahamut45
Last active August 29, 2015 14:04
Show Gist options
  • Save bahamut45/3e322ecfd57ac1af35d0 to your computer and use it in GitHub Desktop.
Save bahamut45/3e322ecfd57ac1af35d0 to your computer and use it in GitHub Desktop.
Tableau Switch
array(2) {
["RG1"]=>
array(2) {
[1]=>
array(4) {
["UNITE"]=>
string(2) "U1"
["IP"]=>
string(11) "10.118.6.30"
["NOM"]=>
string(15) "rca0180007ksw30"
["PARENT"]=>
string(16) "rca0180007ksw126"
}
[2]=>
array(4) {
["UNITE"]=>
string(2) "U2"
["IP"]=>
string(11) "10.118.6.31"
["NOM"]=>
string(15) "rca0180007ksw31"
["PARENT"]=>
string(15) "rca0180007ksw30"
}
}
["RG3"]=>
array(3) {
[1]=>
array(4) {
["UNITE"]=>
string(2) "U1"
["IP"]=>
string(11) "10.118.6.38"
["NOM"]=>
string(15) "rca0180007ksw38"
["PARENT"]=>
string(16) "rca0180007ksw126"
}
[2]=>
array(4) {
["UNITE"]=>
string(2) "U2"
["IP"]=>
string(11) "10.118.6.39"
["NOM"]=>
string(15) "rca0180007ksw39"
["PARENT"]=>
string(15) "rca0180007ksw38"
}
[3]=>
array(4) {
["UNITE"]=>
string(2) "U3"
["IP"]=>
string(12) "10.118.6.100"
["NOM"]=>
string(16) "rca0180007ksw100"
["PARENT"]=>
string(15) "rca0180007ksw39"
}
}
}
<?php
$coeur = 'rca0180007ksw126';
$parent = array(
"RG1" => array(
// L'index 1 n'est pas créé naturellement mais je fais un substring de l'unité dans la boucle qui precede ce tableau
1 => array(
"UNITE"=> "U1",
"IP"=> "10.118.6.30",
"NOM"=> "rca0180007ksw30"
),
2 => array(
"UNITE"=> "U2",
"IP"=> "10.118.6.31",
"NOM"=> "rca0180007ksw31"
)
),
"RG3"=> array(
1 => array(
"UNITE"=> "U1",
"IP"=> "10.118.6.38",
"NOM"=> "rca0180007ksw38"
),
2 => array(
"UNITE"=> "U2",
"IP"=> "10.118.6.39",
"NOM"=> "rca0180007ksw39"
),
3 => array(
"UNITE"=> "U3",
"IP"=> "10.118.6.100",
"NOM"=> "rca0180007ksw100"
)
)
);
foreach ($parent as $key => $value) {
foreach ($value as $k => $v) {
if ($v['UNITE'] == 'U1') {
$parent[$key][$k]['PARENT'] = $coeur;
}else{
$unit = $k - 1;
$parent[$key][$k]['PARENT'] = $parent[$key][$unit]['NOM'];
}
}
}
var_dump($parent);
?>
@bahamut45
Copy link
Author

Le but c'est que pour chaque baie (RG1, RG3) le switch U1 a un champ parent que je choisi mais que le switch U2 est un champ parent correspondant au nom du U1 et pareil pour le switch U3 est un champ parent correspondant au nom de U2.

@Glaived
Copy link

Glaived commented Jul 23, 2014

<?php
$parent = array(
    'RG1' => array(
        ID0000001 => array(
            'UNITE' => 'U1',
            'IP'    => '10.118.6.30',
            'NOM'   => 'rca0180007ksw30',
            'LINK'   => '----------TON_ID_ICI----------',
        ),
        ID0000002 => array(
            'UNITE' => 'U2',
            'IP'    => '10.118.6.31',
            'NOM'   => 'rca0180007ksw31',
            'LINK'  => 'ID0000001', // Le lien
        )
    ),
    'RG3'=> array(
        ID0000003 => array(
            'UNITE' => 'U1',
            'IP'    => '10.118.6.38',
            'NOM'   => 'rca0180007ksw38',
            'LINK'  => '----------TON_ID_ICI----------',
        ),
        ID0000004 => array(
            'UNITE' => 'U2',
            'IP'    => '10.118.6.39',
            'NOM'   => 'rca0180007ksw39',
            'LINK'  => 'ID0000003', // Le lien
        ),
        ID0000005 => array(
            'UNITE' => 'U3',
            'IP'    => '10.118.6.100',
            'NOM'   => 'rca0180007ksw100',
            'LINK'  => 'ID0000004', // Le lien
        )
    )
);

@bahamut45
Copy link
Author

<?php

$parent = array(
    "RG1" => array(
        1 => array(
            "UNITE"=> "U1",
            "IP"=> "10.118.6.30",
            "NOM"=> "rca0180007ksw30"
            "PARENT"=>"rca0180007ksw126"
        ),
        2 => array(
            "UNITE"=> "U2",
            "IP"=> "10.118.6.31",
            "NOM"=> "rca0180007ksw31"
            "PARENT"=>"rca0180007ksw30"
        )
    ),
    "RG3"=> array(
        1 => array(
            "UNITE"=> "U1",
            "IP"=> "10.118.6.38",
            "NOM"=> "rca0180007ksw38"
            "PARENT"=>"rca0180007ksw126"

        ),
        2 => array(
            "UNITE"=> "U2",
            "IP"=> "10.118.6.39",
            "NOM"=> "rca0180007ksw39"
            "PARENT"=>"rca0180007ksw38"
        ),
        3 => array(
            "UNITE"=> "U3",
            "IP"=> "10.118.6.100",
            "NOM"=> "rca0180007ksw100"
            "PARENT"=>"rca0180007ksw39"
        )
    )
);

?>

Le resultat final c'est ça que je veux obtenir mon probleme c'est comment je fait le foreach pour arriver à ce resultat xD

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment