O
O
Optimus2014-07-17 20:59:00
PHP
Optimus, 2014-07-17 20:59:00

How to convert array elements to integer?

I have an array:
array(2) {
[0]=>
string(2) "62"
[1]=>
string(2) "63"
}
How to convert all its elements from string to integer?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey, 2014-07-17
@rdifb0

Why would you need that in a dynamically typed language?
But if you suddenly need something
$array = array_map('intval', $array);

I
iamnothing, 2014-07-17
@iamnothing

run through the array and do intval($value) or (int)$value, they say that the second one works faster

foreach ($array as &$row) {
    $row = (int)$row;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question