LMSouq
php-dev Open

Convert a comma-delimited string into array of integers?

CW
cwal
1 month ago
3 views
Problem Description
The following code: $string = "1,2,3" $ids = explode(',', $string); var_dump($ids); Returns the array: array(3) { [0]=> string(1) "1" [1]=> string(1) "2" [2]=> string(1) "3" } I need for the values to be of type `int` instead of type `string`. Is there a better way of doing this than looping through the array with `foreach` and converting each `string` to `int`?

AI-Generated Solution

Powered by LMSouq AI · GPT-4.1-mini

✓ Solution Ready
Analyzing problem and generating solution…
Was this solution helpful?
Back to Knowledge Base