N
N
Natapr02015-05-14 15:00:13
MySQL
Natapr0, 2015-05-14 15:00:13

Yii2 how to convert array(string) to array(int)?

I make a query to the database

$sql = 'select COUNT(*) from ... // там еще вложенный внутри запрос с группировкой по дате
Yii::$app->db->createCommand($sql)->queryColumn();

The var_dump array value type returns string, although only numbers are returned.
How to get int in array values?
Can I somehow specify in the selection right away or do I need to convert?
In any case, I'm looking for advice, thanks in advance to everyone!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Mikhail Osher, 2015-05-14
@miraage

$array = array_map('intval', $array);

M
Maxim Grechushnikov, 2015-05-14
@maxyc_webber

php seems to always give strings from the muscle (not sure)
use (int) or intval()
type casting

A
Alexey Volegov, 2015-05-14
@EagleMoor

Well, let's start with the fact that you want to get count (*), where the array was drawn from, I don’t know, maybe sql will give more understanding
This is for extracting 1 scalar value, count is just right =)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question