0
Array
(
    [hid] => 1
    [name] => Leonardo Royal Hotel Berlin Alexanderplatz
    [address] => Otto-Braunstrasse 90, D-10249 Berlin, Germany
    [price_from] => 5,180
    [main_image] => 
    [latitude] => 52.5271842
    [longitude] => 13.4214713,17
    [images] => Array
        (
            [0] => LeonardoRoyalHotelBerlinAlexanderplatz-800-600-1.jpg
            [1] => LeonardoRoyalHotelBerlinAlexanderplatz-800-600-2.jpg
            [2] => LeonardoRoyalHotelBerlinAlexanderplatz-800-600-3.jpg
            [3] => LeonardoRoyalHotelBerlinAlexanderplatz-800-600-4.jpg
        )

)

I have an array like this. How can i search word like "Berlin" from array value ?

Shefali
  • 490
  • 4
  • 16
  • 9
    Possible duplicate of [Search for partial value match in an Array](http://stackoverflow.com/questions/6932438/search-for-partial-value-match-in-an-array) – Scuzzy Feb 13 '17 at 10:11
  • @shefali-prajapati Do you want to search that this word is exists (so function will return true or false) or do you want key that value is berlin. – Apoorva Shah Feb 25 '17 at 18:00
  • @ApoorvaShah i want to return true or false. – Shefali Feb 27 '17 at 05:24

2 Answers2

1

You can use array_walk_recursive if you does not want to know just berlin is exists in some key. If you want something more info please comment.

$data = 'Your array here';
$str = 'Berlin';

array_walk_recursive($data, function($item, $key) use ($str) {
   if (stripos($item, $str) !== false) {
       echo $key; // or any action you want.
   }
});

If something is printed then Berlin is exist in some key.

Apoorva Shah
  • 632
  • 1
  • 6
  • 15
-1

Hope this code helps

<?php
$a=array("red folk","green book","blue");
 $match="book";
 $searchedValue="";
   foreach($a as $key=>$val){
   if(strpos($val,$match)) {
   $searchedValue=$val;
  }
  }
 echo $searchedValue;
geekbro
  • 1,293
  • 12
  • 13