par
AB » 10 juin 2009, 21:26
Alors un truc comme ça peut-être
<?php
$a = array
(
0 => 'ID_PAGE',
1 => 'LIBELLE',
2 => 'ID_PAGE',
3 => 'LIBELLE',
4 => 'ID_PAGE',
5 => 'LIBELLE'
);
$b = array
(
0 => '13456',
1 => 'test 1',
2 => '23456',
3 => 'test 2',
4 => '33456',
5 => 'test 3',
);
$result = array();
$i = 0;
foreach ($a as $key => $value) {
if (isset($result[$i]) && array_key_exists($value,$result[$i]))
$result[++$i][$value] = $b[$key];
else
$result[$i][$value] = $b[$key];
}
echo '<pre>';
print_r($result);
echo '</pre>';
/*Affiche :
Array
(
[0] => Array
(
[ID_PAGE] => 13456
[LIBELLE] => test 1
)
[1] => Array
(
[ID_PAGE] => 23456
[LIBELLE] => test 2
)
[2] => Array
(
[ID_PAGE] => 33456
[LIBELLE] => test 3
)
)
*/
?>
Enfin bon ce qui compte aussi c'est de partir avec des tableaux cohérents dès le départ et là la base me paraît un peu risquée.
Alors un truc comme ça peut-être
[php]<?php
$a = array
(
0 => 'ID_PAGE',
1 => 'LIBELLE',
2 => 'ID_PAGE',
3 => 'LIBELLE',
4 => 'ID_PAGE',
5 => 'LIBELLE'
);
$b = array
(
0 => '13456',
1 => 'test 1',
2 => '23456',
3 => 'test 2',
4 => '33456',
5 => 'test 3',
);
$result = array();
$i = 0;
foreach ($a as $key => $value) {
if (isset($result[$i]) && array_key_exists($value,$result[$i]))
$result[++$i][$value] = $b[$key];
else
$result[$i][$value] = $b[$key];
}
echo '<pre>';
print_r($result);
echo '</pre>';
/*Affiche :
Array
(
[0] => Array
(
[ID_PAGE] => 13456
[LIBELLE] => test 1
)
[1] => Array
(
[ID_PAGE] => 23456
[LIBELLE] => test 2
)
[2] => Array
(
[ID_PAGE] => 33456
[LIBELLE] => test 3
)
)
*/
?>[/php]
Enfin bon ce qui compte aussi c'est de partir avec des tableaux cohérents dès le départ et là la base me paraît un peu risquée.