Azad Chouhan
Azad Chouhan

Reputation: 79

How to filter the array in php based on elements

Can any body please tell me how to filter this array. I want to show only those records in which hide_chat_1 or hide_chat_2 are 0.I does not want hide_chat_1 or hide_chat_2 of value 1

Array(
    [0] => Array(
        [unread_msg] => 0[user_id] => 524[c_id] => 152[first_name] => Sanjay . palial@gmail . com[last_name] => Palial[user_name] => sanjay . palial@gmail . com[loginstatus] => 1[user_one] => 524[user_two] => 19[user_img] => [property_id] => 1571[locality] => Sector125[city] => Mohali[online_status] => 0[hide_chat_1] => 0[hide_chat_2] => 0
    ) [1] => Array(
        [unread_msg] => 0[user_id] => 465[c_id] => 151[first_name] => Alvinseo[last_name] => Verma[user_name] => alvinseo[loginstatus] => 1[user_one] => 465[user_two] => 19[user_img] => 296_IMG20150607083310 . jpg[property_id] => 1571[locality] => Sector125[city] => Mohali[online_status] => 0[hide_chat_1] => 0[hide_chat_2] => 1
    ) [2] => Array(
        [unread_msg] => 0[user_id] => 519[c_id] => 138[first_name] => ATSGolf[last_name] => Meadows[user_name] => atsgolfmeadows[loginstatus] => 1[user_one] => 19[user_two] => 519[user_img] => 705_2F79BB9221B2F96F7305AA96D01DD9EBD96BE4B0D7506F9954pimgpshfullsizedistr . png[property_id] => 1526[locality] => BarwalaRoad,
        Derabassi[city] => Derabassi[online_status] => 0[hide_chat_1] => 0[hide_chat_2] => 0
    ) [3] => Array(
        [unread_msg] => 0[user_id] => 504[c_id] => 134[first_name] => Mandeep[last_name] => Talwar[user_name] => mandy[loginstatus] => 0[user_one] => 19[user_two] => 504[user_img] => [property_id] => 1485[locality] => Sector114[city] => Mohali[online_status] => 0[hide_chat_1] => 1[hide_chat_2] => 0
    )
)

It may be looks silly or easy questions for some of you. But any help is appreciable.

Upvotes: 0

Views: 30

Answers (1)

Dev Danidhariya
Dev Danidhariya

Reputation: 713

Try This

$results is your Array

$new_result =  array();
    foreach ($results as $value) {
        if($value['hide_chat_1'] == '0' || $value['hide_chat_2'] == '0'){
                $new_result[] = $value; 
        }

}
print_r($new_result);

Upvotes: 1

Related Questions