Reputation: 645
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, Thanks..
Upvotes: 0
Views: 150
Reputation: 212412
If you're using PHP 5.5, then you can use array_column()
$result = array_column($myArrayRecords, 'cod');
Upvotes: 1
Reputation: 1892
$result = array();
foreach ($your_array as $row) {
$result[] = $row['cod'];
}
// $result = array('SS','CC','NN');
Upvotes: 1