¿Cómo cambio los valores clave en una matriz php [duplicado]?

Posible duplicado:
Changing a nested (multidimentional) array into key => value pairs in PHP

Tengo esta matriz

[5] => Array
        (
            [completed_system_products_id] => 1
            [completed_systems_id] => 76
            [step_number] => 1
            [product_id] => 92
            [category] => hardware
            [date_added] => 2011-05-03 13:44:01
        )

    [4] => Array
        (
            [completed_system_products_id] => 2
            [completed_systems_id] => 76
            [step_number] => 2
            [product_id] => 62
            [category] => hardware
            [date_added] => 2011-05-03 13:44:51
        )

    [3] => Array
        (
            [completed_system_products_id] => 3
            [completed_systems_id] => 76
            [step_number] => 3
            [product_id] => 104
            [category] => hardware
            [date_added] => 2011-05-03 13:44:56
        )

    [2] => Array
        (
            [completed_system_products_id] => 4
            [completed_systems_id] => 76
            [step_number] => 4
            [product_id] => 251
            [category] => hardware
            [date_added] => 2011-05-03 13:48:56
        )

How do i make the keys values the same as the [step_number] =>

so for example i want this outcome

    [1] => Array
        (
            [completed_system_products_id] => 1
            [completed_systems_id] => 76
            [step_number] => 1
            [product_id] => 92
            [category] => hardware
            [date_added] => 2011-05-03 13:44:01
        )

    [2] => Array
        (
            [completed_system_products_id] => 2
            [completed_systems_id] => 76
            [step_number] => 2
            [product_id] => 62
            [category] => hardware
            [date_added] => 2011-05-03 13:44:51
        )

    [3] => Array
        (
            [completed_system_products_id] => 3
            [completed_systems_id] => 76
            [step_number] => 3
            [product_id] => 104
            [category] => hardware
            [date_added] => 2011-05-03 13:44:56
        )

    [4] => Array
        (
            [completed_system_products_id] => 4
            [completed_systems_id] => 76
            [step_number] => 4
            [product_id] => 251
            [category] => hardware
            [date_added] => 2011-05-03 13:48:56
        )

preguntado el 08 de noviembre de 11 a las 14:11

3 Respuestas

$new = array();
foreach ($old as $value) {
    $new[$value['step_number']] = $value;
}
$old = $new;

respondido 08 nov., 11:18

$result = array(); // Create a new array to hold the result
foreach ($array as $val) { // Loop the original array
  $result[$val['step_number']] = $val; // Add the value to the new array with the correct key
}
ksort($result); // Sort the array by key
print_r($result); // Display the result

respondido 08 nov., 11:18

$results = array();
foreach ($array as $item)
{
  $results[$item['step_number']] = $item;
}

respondido 19 nov., 12:13

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.