php - How to search value for a condition inside an array -


given array:

array (     [0] => array         (             [footer] => array                 (                     [id] => 1                     [field] =>                     [fvalue] =>  dream change our country. nmnmn                    )          )      [1] => array         (             [footer] => array                 (                     [id] => 2                     [field] => contact                     [fvalue] =>                    <h2>our contacts</h2>                  <address class="margin-bottom-40">                      shekertek, road: #3 <br>                      dhaka, bangladesh<br>                      phone: 01673050495<br>                      email: <a href="jegeachi24@gmail.com">jegeachi24@gmail.com</a><br>                      skype: <a href="skype:jegeachi.support">jegeachi.support</a>                  </address>                      )          )  ) 

here 2 elements. elements may 10 or more. want value of 'fvalue' index inside array given value of 'field' index. example, if give 'about' array give me 'we dream change our country. nmnmn' how can this.

i have 2 options you:

$searchfield = 'about'; $key = array_search($searchfield, array_column(array_column($arr, 'footer'), 'field')); echo $arr[$key]['footer']['fvalue']; 

or

$searchfield = 'about'; $result = array_filter(array_column($arr, 'footer'), function($arr) use($searchfield){return $arr['field'] == $searchfield;}); echo $result[0]['fvalue']; 

Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -