2017-05-24 18 views
-2

私は配列を持っています。検索結果をPHPの配列から取得するには?

Array 
(
    [0] => Array 
     (
      [0] => <img src='http://dev-gym-management.pantheonsite.io/wp-content/uploads/2017/03/images-5 
.jpg' height='50px' width='50px' class='img-circle'/> 
      [1] => Anna Khan 
      [2] => Personal Trainer 
      [3] => [email protected] 
      [4] => 990099000 
      [5] => <a href='?page=gmgt_staff&tab=add_staffmember&action=edit&staff_member_id=5 class 
='btn btn-info'>Edit</a><a href='?page=gmgt_staff&tab=staff_memberlist&action=delete&staff_member_id 
=5' class='btn btn-danger'>Delete</a> 
     ) 

) 

私は、検索配列にしようとしているが、正常に動作していないよ。私は「アンナ・カーン」で検索したい場合は

Array 
(
    [0] => Array 
     (
      [0] => <img src='http://dev-gym-management.pantheonsite.io/wp-content/uploads/2017/03/images-5 
.jpg' height='50px' width='50px' class='img-circle'/> 
      [1] => Anna Khan 
      [2] => Personal Trainer 
      [3] => [email protected] 
      [4] => 990099000 
      [5] => <a href='?page=gmgt_staff&tab=add_staffmember&action=edit&staff_member_id=5 class 
='btn btn-info'>Edit</a><a href='?page=gmgt_staff&tab=staff_memberlist&action=delete&staff_member_id 
=5' class='btn btn-danger'>Delete</a> 
     ) 

    [1] => Array 
     (
      [0] => <img src='http://dev-gym-management.pantheonsite.io/wp-content/uploads/2017/03/images-4 
.jpg' height='50px' width='50px' class='img-circle'/> 
      [1] => Jobaer Rahman 
      [2] => Personal Trainer 
      [3] => [email protected] 
      [4] => 55555555 
      [5] => <a href='?page=gmgt_staff&tab=add_staffmember&action=edit&staff_member_id=3 class 
='btn btn-info'>Edit</a><a href='?page=gmgt_staff&tab=staff_memberlist&action=delete&staff_member_id 
=3' class='btn btn-danger'>Delete</a> 
     ) 

    [2] => Array 
     (
      [0] => <img src='http://dev-gym-management.pantheonsite.io/wp-content/uploads/2017/03/images-3 
.jpg' height='50px' width='50px' class='img-circle'/> 
      [1] => Milon Khan 
      [2] => Fitness Instructors 
      [3] => [email protected] 
      [4] => 7777777888 
      [5] => <a href='?page=gmgt_staff&tab=add_staffmember&action=edit&staff_member_id=4 class 
='btn btn-info'>Edit</a><a href='?page=gmgt_staff&tab=staff_memberlist&action=delete&staff_member_id 
=4' class='btn btn-danger'>Delete</a> 
     ) 

) 

は今、私のような結果を必要としています。複雑さを軽減するために、私は生のコードを使用しません。任意の最も簡単な方法やこれを行うPHPの配列関数?

+0

はhttp://php.net/manual/en/function.array-search.php#116635 –

+0

https://stackoverflow.com/questions/6932438/search-for-partial例に見てみましょう配列内の値の一致これを確認する必要があると思います。 – Shefali

答えて

0
$data = [array here]; 
$search_str = 'Anna Khan'; 

array_walk_recursive($data, function($item, $key) use ($search_str) { 
    if (stripos($item, $search_str) !== false) { 
     echo $key; // or any action you want. 
    } 
}); 
関連する問題