I have a problem to understand why this doesn't work. I have recursive function who check if value in multidimensional array exists.
Then I have get_teams() function from which I want to return only unique values. I check for unique values with my find_value() function but it still return all the values.. Can someone explain me what happens? Thanks in advance
function find_value( $array, $searched_val ) {
foreach ( $array as $key => $val ) {
if ( $val === $searched_val ) {
return true;
}
if ( is_array( $val ) ) {
return find_value( $val, $searched_val );
}
}
return 0;
}
get_teams();
function get_teams() {
$people = get_data( 'some/file.json' );
$teams = [];
foreach ( $people as $person ) {
if ( ! find_value( $teams, $person['team'] ) ) {
$teams[] = [ 'text' => $person['team'] ];
}
}
return $teams;
}
This is sample input
Array
(
[0] => Array
(
[id] => 1
[name] => Friedrich Robel
[team] => WordPress
[position] => Frontend Developer
[salary] => 4400
)
[1] => Array
(
[id] => 2
[name] => Mr. Christop Veum
[team] => HTML
[position] => Manager
[salary] => 1200
)
[2] => Array
(
[id] => 3
[name] => Demarco Rippin
[team] => HTML
[position] => QA
[salary] => 4400
)
[3] => Array
(
[id] => 4
[name] => Felicia Farrell
[team] => HTML
[position] => QA
[salary] => 1200
)
[4] => Array
(
[id] => 5
[name] => Torrance Fritsch
[team] => HTML
[position] => Assistant Manager
[salary] => 2500
)
[5] => Array
(
[id] => 6
[name] => Erica Daugherty
[team] => Mail
[position] => Assistant Manager
[salary] => 500
)
)
And I want this output
Array
(
[0] => WordPress,
[1] => HTML,
[2] => Mail
)