When a loop is used, empty data is added to the two arrays. How can we filter out empty data in a loop?
If it is determined in the loop body, if it is null, the loop after this loop does not show data continues
For example:
Foreach ($ array as $ value ){
If (empty ($ value ))
Continue;
}
The PHP code is as follows:
/**
@ Document category includes Level 2
@ Param int $ rootnum -- number of hash classes
@ Param int $ childnum -- number of second-level classes
@ Return value array
@ Date 2011.2.24
*/
Function temp_articletreecate ($ rootnum, $ childnum ){
If (! Isnumber ($ rootnum )){
$ Rootnum = 10;
}
If (! Isnumber ($ childnum )){
$ Childnum = 10;
}
$ Category = array ();
$ Parent_ SQL = "SELECT cateid, catename FROM". TABLE_PREFIX. "articlecate WHERE
Parentid = 0 AND depth = 0 AND flag = 1 order by orders ASC ";
If (intval ($ rootnum)> 0 ){
$ Parent_ SQL. = "LIMIT $ rootnum ";
}
$ Parent_cate = $ GLOBALS ['DB']-> getall ($ parent_ SQL );
Foreach ($ parent_cate as $ parent_key => $ parent_value ){
// The subclass array name is childcategory, which can be customized as needed
$ Category [] = array ('cateid' => $ parent_value ['cateid'], 'catename' => $ parent_value
['Catename'], 'childcategory '=> array ());
// Read subclass
$ Child_ SQL = "SELECT cateid, catename FROM". TABLE_PREFIX. "articlecate WHERE
Parentid = ". $ parent_value ['cateid']." AND flag = 1 order by orders ASC ";
If (intval ($ childnum)> 0 ){
$ Child_ SQL. = "LIMIT $ childnum ";
}
$ Child_cate = $ GLOBALS ['DB']-> getall ($ child_ SQL );
Foreach ($ child_cate as $ child_key => $ child_value ){
$ Category [count ($ category)-1] ['childcategory '] [] = array ('cateid' => $ child_value
['Cateid'], 'catename' => $ child_value ['catename']);
}
}
Return $ category;
}
Php Tutorial: smarty foreach function **/
$ Tpl = new Smarty ();
$ Tpl-> template_dir = $ cfg ['path'] ['template'];
$ Tpl-> compile_dir = $ cfg ['path'] ['root']. 'Www .111cn.net/111cn /';
$ Tpl-> compile_check = $ cfg ['debug'];
$ Tpl-> debugging = false;
$ Tpl-> caching = 0;
$ Tpl-> cache_lifetime = 6000;
$ Tpl-> left_delimiter = '<! --{';
$ Tpl-> right_delimiter = '} --> ';
// Configure smarty
$ Db = new Db ();
Try {
$ Query = $ Db-> query ($ SQL );
If ($ Db-> rows ($ query ))
{
$ Array = $ Db-> fetch ($ query, 0 );
Foreach ($ array as $ v =>$ _ v)
{
$ List [$ v] ['id'] = $ _ v [0];
$ List [$ v] ['cntitle'] = $ _ v [2];
$ List [$ v] ['I'] = $ I ++;
}
}
} Catch (Execption $ e ){
MessAge ('Call parameter failed! ');
}
// Php processing and programs
Tpl-> assign ('jsmenu _ Deng', $ List );
// The following process foreach for The smarty Template
<! -- {Foreach from = $ jsMenu_Deng item = item key = key} -->
Subcat [<! -- {$ Item. I} -->] = new Array ("<! -- {$ Item. cntitle} --> "," <! -- {$ Item. upid}
--> "," <! -- {$ Item. id} --> ");
<! -- {/Foreach} -->
Var onecount = <! -- {$ Item. I} -->;
// In fact, it is very easy to save the data in php and then implement it by smarty foreach.