Search
 
SCRIPT & CODE EXAMPLE
 

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)));
Comment

PREVIOUS NEXT
Code Example
Php :: php object 
Php :: php submit form in new tab 
Php :: how to named route resource laravel 
Php :: file could not be downloaded: Unable to find the wrap per "https" - did you forget to enable it when you configured PHP? failed to open stream: No such file or directory 
Php :: get user by meta wp 
Php :: array pop php 
Php :: laravel eloquent get specific columns using with function 
Php :: how to get index 2nd php 
Php :: laravel drop foreign column 
Php :: laravel route multiple methods 
Php :: laravel update from 7 to 8 
Php :: laravel 8 query builder 
Php :: php sha512 hash 
Php :: guzzle get request 
Php :: md5 (PHP 4, PHP 5, PHP 7, PHP 8) md5 — Calculate the md5 hash of a string 
Php :: php meta refresh 
Php :: laravel blade routeIs 
Php :: laravel get column field name 
Php :: how to add page link in laravel 
Php :: laravel relation select fields 
Php :: add controller to laravel with requests 
Php :: php sort array by value 
Php :: taxonomy_get_parents drupal 8 
Php :: laravel create model 
Php :: php decode json object 
Php :: laravel passport vue 401 Unauthorized 
Php :: php sprintf 
Php :: pdf to image php 
Php :: while true php 
Php :: How To Unset Or Delete An Element From Array By Value In PHP? 
ADD CONTENT
Topic
Content
Source link
Name
7+9 =