J'ai deux tableaux comme suit.Aplatir le tableau multidimensionnel ne fonctionne pas
$alerts_array=array(1) {
[0]=> array(11) {
["CustomAlertsID"]=> int(3)
["CustomAlerts_Name"]=> string(10) "title demo"
["CustomAlerts_PublishDate"]=> string(10) "2016-07-03"
["CustomAlerts_ExpiryDate"]=> string(10) "2016-07-21"
}
}
$singlebtn_array =array(3) {
["button_text0"]=> string(16) "Button Name1only"
["button_text1"]=> string(12) "button name2"
["button_text2"]=> string(16) "button name3_new"
}
J'ai fusionné les deux tableaux en un seul tableau multidimensionnel qui ressemble à la suite
$alerts_array = array_merge($alerts_array,$singlebtn_array);
array(4) { [0]=> array(11)
{ ["CustomAlertsID"]=> int(3)
["CustomAlerts_Name"]=> string(10) "title demo"
["CustomAlerts_PublishDate"]=> string(10) "2016-07-03"
["CustomAlerts_ExpiryDate"]=> string(10) "2016-07-21"
}
[1]=> array(1)
{ ["button_text0"]=> string(16) "Button Name1only" }
[2]=> array(1)
{ ["button_text1"]=> string(12) "button name2" }
[3]=> array(1) { ["button_text2"]=> string(16) "button name3_new" } }
J'ai besoin les clés et les valeurs dans le nouveau tableau aplaties
J'ai besoin comme ceci:
array(4) { [0]=> array(11)
{ ["CustomAlertsID"]=> int(3)
["CustomAlerts_Name"]=> string(10) "title demo"
["CustomAlerts_PublishDate"]=> string(10) "2016-07-03"
["CustomAlerts_ExpiryDate"]=> string(10) "2016-07-21"
["button_text0"]=> string(16) "Button Name1only"
["button_text1"]=> string(12) "button name2"
["button_text2"]=> string(16) "button name3_new" }}
J'ai utilisé le code suivant pour la combinaison.
$newArr = array();
foreach ($alerts_array as $key=>$tmp) {
$newArr = array_merge($newArr, array_values($tmp));
}
Le $newArr
me donne le résultat, mais les clés sont perdues
Cela ne fonctionne pas comme requis pour moi – Techy
Ensuite, s'il vous plaît montrer quelques exemples pertinents/parties de votre code. Cela fait exactement ce que votre question stipule. – Oldskool
Le résultat est le suivant: {["CustomAlertsID"] => int (3) ["CustomAlerts_Name"] => chaîne (10) "title demo" "[" CustomAlerts_PublishDate "] => chaîne (10)" 2016- 07-03 "[" CustomAlerts_ExpiryDate "] => chaîne (10)" 2016-07-21 "[0] => array (1) {[" button_text0 "] => chaîne (16)" Button Name1only "} [1 ] => array (1) {["button_text1"] => chaîne (12) "bouton nom2"} [2] => array (1) {["button_text2"] => chaîne (16) "bouton name3_new"} } – Techy