php - Foreach issue with empty variables -
php - Foreach issue with empty variables -
i'd refer original question: populating calendar php foreach code
when working on localhost server, script works, when uploaded online, calendar not appear, , chrome gives me next errors:
<b>warning</b>: array_values() [<a href='function.array-values'>function.array-values</a>]: argument should array in <b>/home/flyeurov/public_html/lib/skins/flyeuro/events/events_index.tpl</b> on line <b>30</b> <b>warning</b>: array_merge() [<a href='function.array-merge'>function.array-merge</a>]: argument #2 not array in <b>/home/flyeurov/public_html/lib/skins/flyeuro/events/events_index.tpl</b> on line <b>30</b> <b>warning</b>: invalid argument supplied foreach() in <b>/home/flyeurov/public_html/lib/skins/flyeuro/events/events_index.tpl</b> on line <b>30</b><br />
i have discovered happening when have no events happening in past = $history
hence empty, or events planned future = $events
empty.
foreach(array_merge(array_values($history), array_values($events)) $event)
but scheme bound not have events planned, hence empty $event
, question is, how can bypass foreach display calendar anyway 1 or other empty variable?
if(!empty($history) || !empty($events)){ foreach(array_merge(array_values($history), array_values($events)) $event){...} }
in case improve solution(removed if condition) :
$history = (!empty($history))?$history:array(); $events = (!empty($events))?$events:array(); foreach(array_merge(array_values($history), array_values($events)) $event){...}
php
Comments
Post a Comment