Question: Why is the variable $myVar undefined in the for loop statement while defined in the if statement as shown below (blade template in Laravel 5.2)? 

```
  $myVar = [];

  @if (empty($myVar))
     Var is empty.
  @endif

  @foreach ($myVar as $var)
    <li>{{$var}}</li>
  @endforeach

```

Answer: 
Please check this out

```
var customerNameDict = ["firstName":"karthi","LastName":"alagu","MiddleName":"prabhu"];
var clientNameDict = ["firstName":"Selva","LastName":"kumar","MiddleName":"m"];
var employeeNameDict = ["firstName":"karthi","LastName":"prabhu","MiddleName":"kp"];

var attributeValue = "karthi";
var arrNames:Array = [customerNameDict,clientNameDict,employeeNameDict];
var namePredicate =NSPredicate(format: "firstName like %@",attributeValue);

let filteredArray = arrNames.filter { namePredicate.evaluateWithObject($0) };
println("names = ,\(filteredArray)");

```
I agree with the comment by @luk2302, in that using the Swift `Array` `filter` method is nicer in general than filtering with an `NSPredicate`. If you're worried about performance across a large data set you should have your content in `CoreData` and use an `NSPredicate` as part of an `NSFetchRequest` with proper indexing setup in your data model.

Having said that, filtering by `NSPredicate` is not explicitly supporting with the Swift `Array` type, so you would have to cast to `NSArray` to use it. It would look something like this:

```
let filteredArray = (arrayofDictionary as NSArray).filteredArrayUsingPredicate(speciesPredicate)

```