Your error comes from these lines:
$salidas = array_push($total,$a);
// ........
if($salidas == "") {
$salida = "No se encontraron las palabras";
} else {
$salida = $salidas;
}
return $salida;
The function array_push returns the number of elements in the array, so it returns 1 if you have one element and so on...
I guess you have to return $total
instead, like:
if($salidas == "") {
$salida = "No se encontraron las palabras";
} else {
$salida = $total;
}
And, also, you have to declare $cuerpo
as a global variable inside the function.