I’ve got a problem in my foreach saying “Invalid argument supplied for foreach in line …”
This is the code I’m working on:
protected function jsGenerateResourcesAutocomplete(){
$employeeNames = $this->employeeNames;
$html = "";
$html .= '<script>' . PHP_EOL;
$html .= 'var employeeNames = [' . PHP_EOL;
foreach( $employeeNames as $employeeName ){
$html .= '"' . $employeeName->getEmployeeName() . '",' . PHP_EOL;
}
$html .= '];' . PHP_EOL;
$html .= '$(function() {' . PHP_EOL;
$html .= '$(#resource-input input:text").each(function() {' . PHP_EOL;
$html .= '$(this).autocomplete({source: employeeNames});' . PHP_EOL;
$html .= '})' . PHP_EOL;
$html .= '})' . PHP_EOL;
$html .= '</script>' . PHP_EOL;
return $html;
}
In this line: foreach( $employeeNames as $employeeName ){ throws the error. What is wrong with this?
Firstly please check $employeeNames this is array or not using
then execute foreach loop