phparrays

How to isolate a column of data from a 2d array?


I have the following array structure...

 Array
(
    [old] => Array
        (
            [ID] => 121
            [cod] => SS
            [tabl] => ss
        )

    [new] => Array
        (
            [ID] => 123
            [cod] => CC
            [tabl] => cc
        )

    [not] => Array
        (
            [ID] => 142
            [cod] => NN
            [tabl] => nn
        )
)

And what I want to achieve was to get the following...

foreach sub array read [cod] and get like this (SS,CC,NN) and then use it in switch like

$a = $_POST['cod'];

switch ($a) foreach (those (SS,CC,NN)) {

case 'SS': do some thing. break;

But what I can't achieve from the above is I can't get the those three sub-array (SS,CC,NN) in this model.

$codes = array (SS,CC,NN) or like

Array
(
    [cod] => SS
    [cod] => CC
    [cod] => NN
)

How do I achieve that?


Solution

  • $result = array();
    foreach ($your_array as $row) {
      $result[] = $row['cod'];
    }
    // $result = array('SS','CC','NN');