phparraysvalidationmultidimensional-array

Check if a 2d array contains a row with a particular column value


I have a array dataImages which holds the arrays of image informations and looks like this

Array ( 
    [0] => Array ( 
        [id] => 104 
        [name] => sample-large-Test-1-a52d268be9ad9c.png 
        [user] => 31 
        [main_image] => 1 
    ) 
    [1] => Array ( 
        [id] => 105 
        [name] => sample-large-Test-1-a52d268bee6ba5.jpg 
        [user] => 31 
        [main_image] => 0 
    ) 
    [2] => Array ( 
        [id] => 106 
        [name] => sample-large-Test-1-a52d268bf4c457.jpg 
        [user] => 31 
        [main_image] => 0 
    ) 
) 

How can I check if in array dataImages is an image with main_image === 1 and how can I show data for that image?


Solution

  • You can do this in loop also:

    foreach ($dataImages as $image){
        if ($image['main_image']) print_r($image)
    }