0

I have this code:

$category = $product->category;
if(!empty($category->category_id)){
  $category = [$category->parent->title,$category->title];
}

it gives result such as:

Default Category first level category 

what i want is to add > between Default Category and first level category

how do i do that?

1 Answer 1

2

Use php's implode function like this $category = implode(" > ", [$category->parent->title,$category->title]);, then you will get your desired result.

Sign up to request clarification or add additional context in comments.

6 Comments

Invalid argument supplied for foreach()
in that case, problem is with your array($category), check it.
dd($category) = "Default Category > first level category"
fixed, the issue was when i use implode i don't need to use foreach anymore.
last thing? how can i add links to each category name of my function?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.