flexicon
flexicon

Reputation: 102

Replace numbers with array

how to put integer values, taken by another array, instead of 1,2,3 like this?

$arr_id = array(1,2,3); //this arr_id go to line 2 instead of 1,2,3
'id' => array('$in' => array(1,2,3))

well, putting $arr_id instead of "1,2,3"... something like this

'id' => array('$in' => array($arr_id))

the problem is that 1,2,3 are number, but in my $arr_id i've strings. If i try to convert string to int i've a problem with "," too

here

array($arr_id))

i need to have integers (not string) taken by $arr_id, separated by ","...

Upvotes: 0

Views: 50

Answers (1)

Neil
Neil

Reputation: 14313

You can convert a string array to an int array in PHP using:

$arr_id_str = array("1","2","3");
var_dump(array_map('intval',$arr_id_str));

Upvotes: 1

Related Questions