Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

find over array object php find

$a = array(
  array(
    'id' => 5698,
    'first_name' => 'Peter',
    'last_name' => 'Griffin',
  ),
  array(
    'id' => 4767,
    'first_name' => 'Ben',
    'last_name' => 'Smith',
  ),
  array(
    'id' => 3809,
    'first_name' => 'Joe',
    'last_name' => 'Doe',
  )
);

$last_names = array_search('Doe', array_column($a, 'last_name'));
print_r($last_names);

$search = 3809;
$found = array_filter($a, function($v, $k) use ($search){
  return $v['id'] == $search;
}, ARRAY_FILTER_USE_BOTH); // With latest PHP third parameter is optional.. Available Values:- ARRAY_FILTER_USE_BOTH OR ARRAY_FILTER_USE_KEY  

print_r(current(array_values($found)));
 
PREVIOUS NEXT
Tagged: #find #array #object #php #find
ADD COMMENT
Topic
Name
1+8 =