public function getOptions($data)
{
$prifix = "|---";
$strOption = [];
foreach($data as $option)
{
$num = $this->getNum($data,$option);
$option['title'] = str_repeat($prifix, $num) . $option['title'];
echo $option['title'];//这里打出来是已经加上了前缀
}
var_dump($data);//这里打出来是原数组没有前缀
return $data;
}
怎么让$data里有前缀??
下面是显示结果:
|---服装|---|---男装|---|---女装|---电子产品|---|---手机|---|---|---苹果array(6) { [0]=> array(3) { ["cateId"]=> string(1) "1" ["title"]=> string(6) "服装" ["parId"]=> string(1) "0" } [1]=> array(3) { ["cateId"]=> string(1) "3" ["title"]=> string(6) "男装" ["parId"]=> string(1) "1" } [2]=> array(3) { ["cateId"]=> string(1) "4" ["title"]=> string(6) "女装" ["parId"]=> string(1) "1" } [3]=> array(3) { ["cateId"]=> string(1) "2" ["title"]=> string(12) "电子产品" ["parId"]=> string(1) "0" } [4]=> array(3) { ["cateId"]=> string(1) "5" ["title"]=> string(6) "手机" ["parId"]=> string(1) "2" } [5]=> array(3) { ["cateId"]=> string(1) "6" ["title"]=> string(6) "苹果" ["parId"]=> string(1) "5" } }
{
$prifix = "|---";
$strOption = [];
foreach($data as $option)
{
$num = $this->getNum($data,$option);
$option['title'] = str_repeat($prifix, $num) . $option['title'];
echo $option['title'];//这里打出来是已经加上了前缀
}
var_dump($data);//这里打出来是原数组没有前缀
return $data;
}
怎么让$data里有前缀??
下面是显示结果:
|---服装|---|---男装|---|---女装|---电子产品|---|---手机|---|---|---苹果array(6) { [0]=> array(3) { ["cateId"]=> string(1) "1" ["title"]=> string(6) "服装" ["parId"]=> string(1) "0" } [1]=> array(3) { ["cateId"]=> string(1) "3" ["title"]=> string(6) "男装" ["parId"]=> string(1) "1" } [2]=> array(3) { ["cateId"]=> string(1) "4" ["title"]=> string(6) "女装" ["parId"]=> string(1) "1" } [3]=> array(3) { ["cateId"]=> string(1) "2" ["title"]=> string(12) "电子产品" ["parId"]=> string(1) "0" } [4]=> array(3) { ["cateId"]=> string(1) "5" ["title"]=> string(6) "手机" ["parId"]=> string(1) "2" } [5]=> array(3) { ["cateId"]=> string(1) "6" ["title"]=> string(6) "苹果" ["parId"]=> string(1) "5" } }