phpyiifilteringphp-7

avoid string element in php 2d array


Desciption:

I have an array 2d:

$array = InvApplication::model()->findall(array('order'=>'app_name'));

The array contents the next element: "app5", How to avoid it?

Actual Output:

app_name|field1|field2|fieldN|..|..
 appn    |
 appn1   |
 appn2   |
 app5    |

Already Tested

I have been testing with unset, in_array and strpos functions. In addition to:

php - finding keys in an array that match a pattern

Delete element from multidimensional-array based on value

My actual piece of code:

This is an actual way, but is not working as I want.

$deleteapp = "app5";
unset($list[$deleteapp]); Test with unset or array_diff
        foreach($list as $k=>$v)
        {
            if(in_array($v,array('app5'))) unset($list[$k]);}

I expect this:

app_name|field1|field2|fieldN|..|..
 appn    |
 appn1   |
 appn2   |

Thank you.


Solution

  • seems you want exclude a app_name from the select result in this case you could use a condition

    $array = InvApplication::model()->findall(
      array("condition"=> "app_name !=  'app5'","order"=>"app_name")
    );