'PHP - I'm Getting an Array to String Conversion Warning When Using Array_Merge
I keep getting an "Array to String" conversion warning when using array_merge(). I don't know why. I've var_dump() the is_array function for $u, $g, $und_schools, and the results of the array_merge function and array_unique function and it always returns true for is_array.
I don't know why I keep getting this error.
Here's the code below. I commented on the lines where I get the error. Anyone have insights?
<?php
$undergrad_schools = array_filter($this->structure["schools"], function ($b) {
foreach ($b as $a) {
if (
(in_array("bachelors", $a["degrees"]) ||
in_array("certificate", $a["degrees"])) &&
$a["info"]["state"] != "PR"
) {
return true;
} elseif (
(in_array("masters", $a["degrees"]) ||
in_array("doctorate", $a["degrees"])) &&
$a["info"]["state"] != "PR"
) {
return false;
} else {
return false;
}
}
});
$grad_schools = array_filter($this->structure["schools"], function ($b) {
foreach ($b as $a) {
if (
(in_array("bachelors", $a["degrees"]) ||
in_array("certificate", $a["degrees"])) &&
$a["info"]["state"] != "PR"
) {
return false;
} elseif (
(in_array("masters", $a["degrees"]) ||
in_array("doctorate", $a["degrees"])) &&
$a["info"]["state"] != "PR"
) {
return true;
} else {
return false;
}
}
});
////// END IGNORE
//flatten the undergrad and grad schools arrays
$und_schools = [];
$grd_schools = [];
//Array to string conversion notice happens on line 37 and line 41 (or where array_merge occurs)
foreach ($undergrad_schools as $u) {
$und_schools = array_merge(array_unique($und_schools), $u);
}
//Array to string conversion notice happens on line 37 and line 41 (or where array_merge occurs)
foreach ($grad_schools as $g) {
$grd_schools = array_merge(array_unique($grd_schools), $g);
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
