I hope they are fine.
I have the following function in PHP that is supposed to be receiving an array but it is taking it as a string.
Can someone help me finding the error please.
This is my code:
public function getCustomfielForSegment($arrIds) {
$arrid = explode(",", $arrIds);
$whereids = array();
foreach ($arraid as $key){
$whereids[] = $key;
}
$where = array("idSegment" => array('$in' => $whereids));
$segment = /Segment::find(where);
$arrIdContactList = array();
foreach ($segment as $key => $val) {
foreach ($val->contactlist as $key) {
$arrIdContactList[] = (Int) $key ['idContactlist'];
}
}
Any help you can give me could be very useful.
Thank you very much
First, use typing , we are not in 2015.
Second, since you don't use typing, no one knows what receives that function, it can be literally almost anything: null, number, object, string... We could maybe infer it by looking at the place where you call the function.
For the first line, it is expected to receive a string with a series of IDs separated by commas.
explode
splits a string into parts, which it inserts into an array .You might expect an array or a string , untyped. In this case it asks for the type before operating, it changes the name of the parameter, eg