Recursive function in php


<1?php

function categorylevelcheck($catid,$array=”) { $con = $this->dbconnect();
$sql = “select * from admin_category a where category_id =’$catid’;” ;
$result = $this->ExecuteMysql($sql,’select’);
if($result[0][‘parentcategory_id’]!=0)
{
$array[]=$result[0][‘category_id’];
$array[]=$result[0][‘category_name’];
return ($this->categorylevelcheck($result[0][‘parentcategory_id’],$array));
}
else
{
$array[]=$result[0][‘category_id’];
$array[]=$result[0][‘category_name’];
if(isset($array))
{
return $array;
}
}

}
?1>

in the above code i get the parent category for every child category.

Advertisements

One comment on “Recursive function in php

  1. Pingback: Recursive function in php « Karuppasamy | Coder Online

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s