0

i have array like this

<?php
$array =
    array
    (
        array (
            0 => 1,
            1 => 'php',
            2 => 11,
            3 => 11,
            4 => 11,
            5 => 11,
            6 => 11,
        ),
        array (
            0 => 1,
            1 => 'php',
            2 => 11,
            3 => 11,
            4 => 11,
            5 => 11,
            6 => ,
        ),

    );

and i want to search in this multi-array to find if the key [6] => is empty.if it was empty in any array return false so how to do this

foreach($array as $item)
{
    foreach($item as $key=>$value)
    {
        print($key);
        if($key=="6" && $value==NULL)
        {
            echo "found";
            return false;
        }else{
            echo "not found";
            return true;
        }
    }
}
5
  • Take a look at this Commented Feb 24, 2015 at 15:16
  • check this out php.net/manual/en/function.empty.php Commented Feb 24, 2015 at 15:16
  • 1
    What's wrong with what you have written? Commented Feb 24, 2015 at 15:18
  • it is not search correctly Commented Feb 24, 2015 at 15:20
  • it is should give me found message because i have empty value in key 6 but it is not give me this message Commented Feb 24, 2015 at 15:22

3 Answers 3

1
$empty = false;
foreach($array as $item)
{
    if(empty($item[6]))
    {
            $empty=true;
            break;
    }
}
return $empty;
Sign up to request clarification or add additional context in comments.

2 Comments

if condition is not closed
@RubinAnbin fixed. Thank you.
0

Comments

0

Here's an alternate for PHP >= 5.5.0 that checks for '', 0, null and false:

return !array_diff($six = array_column($array, 6), array_filter($six));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.