$master-array = Array (
[title] => The Night of the Hunter
[year] => 1955
[box-office] =>
[produced] => United Artists
[mpaa] => Array (
[rating] =>
[locale] => USA
[reason] =>
)
[plot-summary] => ...The Night of the Hunter is now regarded as a classic.
[plot-summary-author] => Hal Erickson
[runtime-min] => 93
[genre] => Array (
[0] => Thriller
[1] => Crime Thriller
[2] => Psychological Thriller
)
)
Hello ! Je voudrais transformer cet array pour obtenir ceci :
$master-array = Array (
[master-array-title] => The Night of the Hunter
[master-array-year] => 1955
[master-array-box-office] =>
[master-array-produced] => United Artists
[master-array-mpaa-rating] =>
[master-array-mpaa-rating] => USA
[master-array-mpaa-rating] =>
[master-array-plot-summary] => ...The Night of the Hunter is now regarded as a classic.
[master-array-plot-summary-author] => Hal Erickson
[master-array-runtime-min] => 93
[master-array-genre-0] => Thriller
[master-array-genre-1] => Crime Thriller
[master-array-genre-2] => Psychological Thriller
)
Mais je me casse les dents, entre les foreach, les keys... c'est vraiment dur !
J'ai trouvé une fonction qui aide, mais je coince pour le "dé-parentage" et la nomenclature des clés.
Merci pour votre aide !
function array_push_associative(&$arr)
{
foreach (func_get_args() as $arg)
{
if (is_array($arg))
foreach ($arg as $key => $value) { $arr[$key] = $value; $ret++; }
else
$arr[$arg] = '';
}
return $ret;
}
(s'utilise comme ça

$unique_item = array($key => $value);
$new_data_full = array_push_associative($new_data_full, $unique_item);
Modifié par gordie (15 Nov 2007 - 12:51)