I have the following array:
$class = array(
'e1' => array('nume' => 'Nitu', 'prenume' => 'Andrei', 'sex' => 'm', 'varsta' => 23),
'e2' => array('nume' => 'Nae', 'prenume' => 'Ionel', 'sex' => 'm', 'varsta' => 27),
'e3' => array('nume' => 'Noman', 'prenume' => 'Alice', 'sex' => 'f', 'varsta' => 22),
'e4' => array('nume' => 'Geangos', 'prenume' => 'Bogdan', 'sex' => 'm', 'varsta' => 23),
'e5' => array('nume' => 'Vasile', 'prenume' => 'Mihai', 'sex' => 'm', 'varsta' => 25)
);
What I would like to do is create a function that can sort this array based on one of its keys, for example, I want the function to sort and output all men ('sex' => 'm'). from an array.
I managed to do this with
foreach ($class as $val) {
if ($val['sex'] == 'm')
echo $val['nume'].' '.$val['prenume'].'<br/>';
}
But I want to create my own function that can do just that, which will help me a lot and give me more information about how the functions work and how they should be performed.
source
share