-1

Hi have a array saved in the variable $someArray. This is the content of $someArray:

Array ( 
    [0] => Array ( 
        [CityDesc] => Burgbretzingen 
        [CityId] => 63910 
    ) 
    [1] => Array ( 
        [CityDesc] => Bühlerzimmern 
        [CityId] => 1288010 
    ) 
    [2] => Array ( 
        [CityDesc] => Einkorn 
        [CityId] => 320610 
    ) 
    [3] => Array 
        ( 
        [CityDesc] => Scherbenmühle 
        [CityId] => 711910 
        )
    [4] => Array ( 
        [CityDesc] => Schwäbisch Hall 
        [CityId] => 1694510 
    ) 
    [5] => Array ( 
        [CityDesc] => Traubenmühle 
        [CityId] => 493610 
    )
)

I will readout the this value 63910 (the [CityId]) if I search for "Burgbretzingen".

wnull
  • 217
  • 6
  • 21
Sinalco
  • 39
  • 5

1 Answers1

2

You can approach it by using array_column

$res = array_column($a, 'CityId', 'CityDesc');
echo empty($res['Burgbretzingen']) ? '' : $res['Burgbretzingen'];

Working example :- https://3v4l.org/s1TNk

Rakesh Jakhar
  • 6,380
  • 2
  • 11
  • 20