2015-11-04 1 views
0

Ceci est mon premier article ici, je travaille actuellement sur un projet de l'école. et im ayant du mal à convertir ce php de tableau multidimensionnel:PHP: convertir un tableau multidimensionnel en un tableau simple

Array 
(
[0] => Array 
    (
     [Program_ID] => 1001 
     [Program_Name] => Computer Engineering 
     [Program_NumHours] => 200 
     [Curriculum_ID] => 101 
    ) 

[1] => Array 
    (
     [Program_ID] => 1002 
     [Program_Name] => Civil Engineering 
     [Program_NumHours] => 200 
     [Curriculum_ID] => 102 
    ) 

[2] => Array 
    (
     [Program_ID] => 1003 
     [Program_Name] => Electronics Engineering 
     [Program_NumHours] => 200 
     [Curriculum_ID] => 103 
    ) 

[3] => Array 
    (
     [Program_ID] => 1004 
     [Program_Name] => Electrical Engineering 
     [Program_NumHours] => 200 
     [Curriculum_ID] => 104 
    ) 
) 

Je veux convertir ce tableau en ceci:

Array 
(
[0] => Array 
    (
     [0] => 1001 
     [1] => Computer Engineering 
     [2] => 200 
     [3] => 101 
    ) 

[1] => Array 
    (
     [0] => 1002 
     [1] => Civil Engineering 
     [2] => 200 
     [3] => 102 
    ) 

[2] => Array 
    (
     [0] => 1003 
     [1] => Electronics Engineering 
     [2] => 200 
     [3] => 103 
    ) 

[3] => Array 
    (
     [0] => 1004 
     [1] => Electrical Engineering 
     [2] => 200 
     [3] => 104 
    ) 
) 

ces données était de la mettre en liberté base de données en utilisant CodeIgniter. Merci d'avance.

+0

je peux être aveugle, mais votre résultat attendu a la même structure/nombre de dimensions que l'entrée - seules les touches du " "tableaux" internes ont été modifiés. – VolkerK

+0

oui, je veux juste convertir le tableau associatif en un tableau simple –

+0

Voir http://stackoverflow.com/questions/15191903/convert-an-associative-array-to-a-simple-array-of-its-values -in-php – noahnu

Répondre

3

voir http://docs.php.net/array_values
et http://docs.php.net/array_map

<?php 
$input = array(
    array('Program_ID' => 1001, 'Program_Name' => 'Computer Engineering', 'Program_NumHours' => 200, 'Curriculum_ID' => 101), 
    array('Program_ID' => 1002, 'Program_Name' => 'Civil Engineering', 'Program_NumHours' => 200, 'Curriculum_ID' => 102), 
    array('Program_ID' => 1003, 'Program_Name' => 'Electronics Engineering', 'Program_NumHours' => 200, 'Curriculum_ID' => 103), 
    array('Program_ID' => 1004, 'Program_Name' => 'Electrical Engineering', 'Program_NumHours' => 200, 'Curriculum_ID' => 104), 
); 

$result = array_map('array_values', $input); 

var_export($result); 

impressions

array (
    0 => 
    array (
    0 => 1001, 
    1 => 'Computer Engineering', 
    2 => 200, 
    3 => 101, 
), 
    1 => 
    array (
    0 => 1002, 
    1 => 'Civil Engineering', 
    2 => 200, 
    3 => 102, 
), 
    2 => 
    array (
    0 => 1003, 
    1 => 'Electronics Engineering', 
    2 => 200, 
    3 => 103, 
), 
    3 => 
    array (
    0 => 1004, 
    1 => 'Electrical Engineering', 
    2 => 200, 
    3 => 104, 
), 
) 
+0

wow c'était rapide. Merci beaucoup! –