fork(2) download
  1. <?php
  2. //your array containing the items.
  3. $aArray = array(
  4. array('Name' => 'Apple', 'Count' => 10),
  5. array('Name' => 'Tomato', 'Count' => 23),
  6. array('Name' => 'Tree', 'Count' => 4),
  7. array('Name' => 'Potato', 'Count' => 44),
  8. array('Name' => 'Apple', 'Count' => 73)
  9. );
  10.  
  11. //the character or string you want to search.
  12. $startWithChar = 'A';
  13.  
  14. //get all items of the array starting with the specified character or string.
  15. $newArray = array_filter($aArray, function($v) use ($startWithChar) {
  16. return strpos($v['Name'], $startWithChar) === 0;
  17. });
  18.  
  19. echo count($newArray); //2
Success #stdin #stdout 0.02s 23484KB
stdin
Standard input is empty
stdout
2