phparraysmultidimensional-array

Determine if a multidimensional array contains a specific column


I have some multidimensional arrays which are declared as $link in a loop.

[
    'width' => 800,
    'height' => 1142,
    'hwstring_small' => "height='96' width='67'",
    'file' => '2010/04/white-1051279.jpg',
    'sizes' => [
        'thumbnail' => [
            'file' => 'white-1051279-100x150.jpg',
            'width' => 100,
            'height' => 150,
        ],
        'medium' => [
            'file' => 'white-1051279-200x285.jpg',
            'width' => 200,
            'height' => 285,
        ],
    ],
    'image_meta' => [
        'aperture' => 0,
        'credit' => '',
        'camera' => '',
        'caption' => '',
        'created_timestamp' => 0,
        'copyright' => '',
        'focal_length' => 0,
        'iso' => 0,
        'shutter_speed' => 0,
        'title' => '',
    ],
]

And

[
    'width' => 50,
    'height' => 50,
    'hwstring_small' => "height='50' width='50'",
    'file' => '2010/04/images1.jpeg',
    'image_meta' => [
        'aperture' => 0,
        'credit' => '',
        'camera' => '',
        'caption' => '',
        'created_timestamp' => 0,
        'copyright' => '',
        'focal_length' => 0,
        'iso' => 0,
        'shutter_speed' => 0,
        'title' => '',
    ],
];

The difference: the first one has a sizes column.

How can I detect that there is a sizes column in given array?

I tried if (in_array("[sizes]", $link)) { } else { }, but it doesn't work.


Solution

  • if(isset($link['sizes'])) {
    
    }
    

    Is this what you're looking for?