I wanted to make sure that this is true. I myself tested this with a very similar query, and my results are very similar:
array(2) { [0]=> array(5) { ["id"]=> string(1) "1" ["name"]=> string(5) "Admin"
In my case, I also get all types as strings. So, if you want to check the input and type with if ($data[0]['id'] === 1) , you will get the result false , since it is string .
But you need to add (int) before the variable in order to convert it to another type. It will be: (int) $data[0]['id'] .
Then var_dump((int) $data[0]['id']); (in my case) will give int(1) instead of string(1) "1" .
You can also check the legend:
((int) $data[0]['id'] === 1) ? exit('Integer') : exit('Not integer');
Without a record (int) prefix will give the result Not integer , and with the prefix, Integer .
If you do not want to write these prefixes in each function, you can write something like:
$data[0]['id'] = (int) $data[0]['id'];
And now $data[0]['id'] will be an Integer for future purposes.
New solution:
This new solution will return an object with arrays instead of arrays.
// Method that gives data back. In this case, user with ID == 10. public static function getData() { $dataProvider = new ActiveDataProvider([ 'query' => self::findOne(['id' => 10])->attributes ]); return $dataProvider; }
In the controller, you (as always) pass this object:
$data = User::getData(); return $this->render('user', [ //... 'data' => $data ]);
And then in Viewer you can access the values ββ(in the correct type) as follows:
$data->query['columnName'];
So, to verify the identifier:
($data->query['id'] === 10 ? exit('ok') : exit('nok'));
You will get the answer ok (typecast: integer, value: 10).