2017-09-13 3 views
0

I持って、私はを検索したい、次のデータ:PHP検索と配列オブジェクトの値をチェックし

Array 
(
    [0] => stdClass Object 
     (
      [id] => 4860 
      [module] => Clients 
      [level] => 2 
      [order] => 1 
      [controller] => home 
      [function] => clients 
      [status] => Active 
      [date_added] => 0000-00-00 00:00:00 
      [time_stamp] => 2017-08-02 09:39:01 
      [description] => Manage the partner clients in the system 
      [span_class] => label btn-metis-6 client_info 
      [icon_class] => icon-user-md icon-2x 
      [created_by] => 1 
      [updated_by] => 
      [partner_id] => 
      [user_id] => 264 
      [module_id] => 6 
      [role_id] => 4 
     ) 

    [1] => stdClass Object 
     (
      [id] => 4865 
      [module] => Appointments 
      [level] => 3 
      [order] => 1 
      [controller] => home 
      [function] => appointments 
      [status] => Active 
      [date_added] => 0000-00-00 00:00:00 
      [time_stamp] => 2017-08-02 09:39:01 
      [description] => View and manage all active Appointments in the System 
      [span_class] => label label-default appointments_info 
      [icon_class] => icon-user 
      [created_by] => 1 
      [updated_by] => 
      [partner_id] => 
      [user_id] => 264 
      [module_id] => 16 
      [role_id] => 4 
     ) 

    [2] => stdClass Object 
     (
      [id] => 4870 
      [module] => Broadcast Report 
      [level] => 7 
      [order] => 1 
      [controller] => home 
      [function] => broadcast_report 
      [status] => Active 
      [date_added] => 0000-00-00 00:00:00 
      [time_stamp] => 2017-08-02 09:39:01 
      [description] => View all the Broadcasts that have been sent out to the clients 
      [span_class] => label label-default broadcast_info 
      [icon_class] => icon-table 
      [created_by] => 1 
      [updated_by] => 
      [partner_id] => 
      [user_id] => 264 
      [module_id] => 53 
      [role_id] => 4 
     ) 

    [3] => stdClass Object 
     (
      [id] => 4861 
      [module] => Add Client 
      [level] => 2 
      [order] => 2 
      [controller] => home 
      [function] => client 
      [status] => Active 
      [date_added] => 0000-00-00 00:00:00 
      [time_stamp] => 2017-08-02 09:39:01 
      [description] => Add new client to the system and at the same time book first appointment for the client. 
      [span_class] => 
      [icon_class] => icon-user icon-2x 
      [created_by] => 1 
      [updated_by] => 
      [partner_id] => 
      [user_id] => 264 
      [module_id] => 8 
      [role_id] => 4 
     ) 

    [4] => stdClass Object 
     (
      [id] => 4863 
      [module] => My Facilities 
      [level] => 7 
      [order] => 2 
      [controller] => admin 
      [function] => my_facilities 
      [status] => Active 
      [date_added] => 0000-00-00 00:00:00 
      [time_stamp] => 2017-08-02 09:39:01 
      [description] => Facilities manager is used to add facilities to a partner's group of Facilities 
      [span_class] => label label-default facility_info 
      [icon_class] => icon-h-sign 
      [created_by] => 1 
      [updated_by] => 
      [partner_id] => 
      [user_id] => 264 
      [module_id] => 12 
      [role_id] => 4 
     ) 

    [5] => stdClass Object 
     (
      [id] => 4869 
      [module] => Adolescents 
      [level] => 5 
      [order] => 2 
      [controller] => home 
      [function] => adolescents 
      [status] => Active 
      [date_added] => 0000-00-00 00:00:00 
      [time_stamp] => 2017-08-02 09:39:01 
      [description] => View the Adolescent client groups 
      [span_class] => label btn-metis-6 groups_info 
      [icon_class] => icon-calendar-empty 
      [created_by] => 1 
      [updated_by] => 
      [partner_id] => 
      [user_id] => 264 
      [module_id] => 38 
      [role_id] => 4 
     ) 

    [6] => stdClass Object 
     (
      [id] => 4858 
      [module] => Users 
      [level] => 6 
      [order] => 3 
      [controller] => admin 
      [function] => users 
      [status] => Active 
      [date_added] => 0000-00-00 00:00:00 
      [time_stamp] => 2017-08-02 09:39:01 
      [description] => User management windows , used to Add, Edit or Delete(mark as In Active) users in the system 
      [span_class] => label btn-metis-4 users_info 
      [icon_class] => icon-user icon-2x 
      [created_by] => 1 
      [updated_by] => 
      [partner_id] => 
      [user_id] => 264 
      [module_id] => 3 
      [role_id] => 4 
     ) 

    [7] => stdClass Object 
     (
      [id] => 4864 
      [module] => Deactivated 
      [level] => 7 
      [order] => 3 
      [controller] => home 
      [function] => deactivated 
      [status] => Active 
      [date_added] => 0000-00-00 00:00:00 
      [time_stamp] => 2017-08-02 09:39:01 
      [description] => List of clients who opted out from the SMS services. 
      [span_class] => label label-default deactivated_info 
      [icon_class] => icon-user 
      [created_by] => 1 
      [updated_by] => 
      [partner_id] => 
      [user_id] => 264 
      [module_id] => 15 
      [role_id] => 4 
     ) 

) 

は、私は、配列を検索し、レベルが存在し、値が何であるかどうかを確認したいと思いますインデックスの は、私は次のことを試してみました:

$number = array_column($array, 'level'); 
$found_key = array_search('2', $number); 

       But I get no response . 

私は、配列を確認し、レベルが存在し、それが保持している値が何であるかどうかを確認する方法上の任意の助けを?

+0

あなたはオブジェクトを正しく意味していますか? – Script47

+0

@ Script47 Yesオブジェクト –

+0

期待される出力の例を追加できますか? –

答えて

1

あなたはそのようなもので、あなたの配列をフィルタリングすることができます。

$filterBy = '2'; 
$newArray = array_filter($array, function ($var) use ($filterBy) { 
    return ($var['level'] == $filterBy); }); 

print_r($newArray); 

$names = array_column($newArray, 'id'); 

print_r($names); 
0

それがオブジェクトであるとして、あなたがそれらにそれらのアレイベースの機能を使用したい場合、あなたは配列型にそれらをキャストする必要があります:

<?php 
$x = new stdClass(); 
$x->y = 'test'; 
$x->z = 'more testing'; 

$array = (array) $x; ----> Is now an array. 
?> 

(配列) - 配列へのキャスト

より良い理解を得るためにthisおよびを参照してください。

0

あなたはこのようforeachループ

を使用することができます。

foreach ($array in $key => $value){ 
    if($value["level"] != ''){ 
     echo $value["level"]; 
    }  
} 
関連する問題